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

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

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,555,780
Community Members
 
Community Events
184
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

0 votes
Gezim Shehu [Communardo]
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Mar 05, 2018 • edited

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
AUG Leaders

Atlassian Community Events