The Atlassian Community Forums are currently in read-only mode. We will be relaunching on a new platform on September 22 (read more here). We apologize for the extended downtime. For concerns or questions, please email communitymanagers@atlassian.com. See you on the other side, on the new Atlassian Community Forums! :)

×

Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Auto-transitioning with Scriptrunner Post-Function during CREATE

Martin Hohenberg
October 15, 2018

I try to cause an auto-transition during the CREATE of a new ticket. The actionId for the transition is 11.


import com.atlassian.jira.bc.issue.IssueService;
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.ComponentManager;
import com.atlassian.jira.issue.MutableIssue;
import com.atlassian.jira.issue.IssueInputParameters;
import com.atlassian.jira.issue.IssueInputParametersImpl;
import com.atlassian.jira.security.JiraAuthenticationContext;
import com.atlassian.jira.user.ApplicationUser;
import com.atlassian.jira.bc.issue.IssueService.IssueResult;

MutableIssue mutIssue = issue;

def businessdepartmentFObj = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Business department")
String businessdepartmentValue = mutIssue.getCustomFieldValue(businessdepartmentFObj).toString();

if (businessdepartmentValue == "No business impact") {
    // no business impact -> get directly into a different status
    final ComponentManager cm = ComponentManager.getInstance();
    IssueService issueService = cm.getComponentInstanceOfType(IssueService.class)
    IssueInputParameters issueInputParameters = new IssueInputParametersImpl([:])

    JiraAuthenticationContext authContext = ComponentAccessor.getJiraAuthenticationContext();
    ApplicationUser origUser = authContext.getLoggedInUser();
    IssueService.TransitionValidationResult transitionValidationResult = issueService.validateTransition(origUser, mutIssue.id, 11 as Integer, issueInputParameters);
    
    if (transitionValidationResult.isValid()) {
        IssueResult transitionResult = issueService.transition(origUser, transitionValidationResult);
        mutIssue.setDescription("Yay")
    } else {
        mutIssue.setDescription("Fail: " + transitionValidationResult.getErrorCollection().toString());
    }
}

 

This code seems to succeed (green tick), but it does not actually do anything. What am I doing wrong?

2 answers

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

1 vote
Daniel Yelamos [Adaptavist]
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Champions.
October 16, 2018

Hi Martin Hohenberg

As Gezim suggested: why don't you use the Scriptrunner built-in post-function "Fast-track transition"?

It's built in and it does what you want it to do.

Check the documentation for it here

Do tell me if I can help you further. 

Cheers!
DYelamos

0 votes
Gezim Shehu [Communardo]
Community Champion
October 16, 2018

I usually use the "old" method to transition, by calling the workflowTransitionUtil

 

WorkflowTransitionUtil workflowTransitionUtil = (WorkflowTransitionUtil) JiraUtils.loadComponent(WorkflowTransitionUtilImpl.class);

workflowTransitionUtil.setIssue(mutableParentIssue);
workflowTransitionUtil.setUserkey('userkey');
workflowTransitionUtil.setAction(actionID);
workflowTransitionUtil.validate();
workflowTransitionUtil.progress();

 

However, in your case, I would suggest to simply use the built-in post function

"Fast Track Transition Issue". Much more convenient and you just need to specify the condition and action ID.


Let me know