Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Auto transition based on custom field value with Groovy script

Hi 

I working on project, where issue must change status automatically based on custom field value set on previous step. I try do this by Automation for Jira Add-on, but it work too slowly and I want to use Script Runner to this. I use Fast-track transition an issue  but I would have to use several such functions. So i try to do this by this script, problem is that doesn't work, can you tell me what I do wrong?

 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.IssueImpl
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.project.ProjectManager
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.user.UserUtils
import com.atlassian.jira.workflow.WorkflowTransitionUtil;
import org.apache.log4j.Category
import com.atlassian.jira.issue.comments.CommentManager
import com.opensymphony.workflow.WorkflowContext
import com.atlassian.jira.workflow.WorkflowTransitionUtil;
import com.atlassian.jira.workflow.WorkflowTransitionUtilImpl;
import com.atlassian.jira.util.JiraUtils;
//boolean status = false
WorkflowTransitionUtil workflowTransitionUtil = ( WorkflowTransitionUtil ) JiraUtils.loadComponent( WorkflowTransitionUtilImpl.class );

IssueManager issueManager = ComponentAccessor.getIssueManager()
CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager()
CustomField myCustomField = customFieldManager.getCustomFieldObjectByName("Category")
String myCustomFieldVal = (String) issue.getCustomFieldValue(myCustomField)
if(myCustomFieldVal.equals("IT"))
{
workflowTransitionUtil.setAction (5)
}

 

1 answer

To transition correctly following lines are needed

 

 workflowTransitionUtil.setIssue(mutableIssue);
workflowTransitionUtil.setUserkey('userToTransition');
workflowTransitionUtil.setAction(actionID);
workflowTransitionUtil.validate();
workflowTransitionUtil.progress();

 

And generally speaking, your import lines should be less than your code lines :P.

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Jira

Admins, notify your Jira instance of system-wide changes with the new admin announcement banner

Hi All! We’re excited to share the launch of an announcement banner that lets Jira site administrators communicate directly to their users across their  Jira Cloud instance.  ...

779 views 17 21
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you