Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,360,041
Community Members
 
Community Events
168
Community Groups

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

Online AMA this week: Your project management questions answered by Jira Design Lead James Rotanson

We know that great teams require amazing project management chops. It's no surprise that great teams who use Jira have strong project managers, effective workflows, and secrets that bring planning ...

181 views 1 6
Read article

Atlassian Community Events