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?
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
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.