I've been trying to use Script Runner's post function to put the issue through a transition depending on the priority they've input. The issue does transition correctly, however the status stays the same even though it is at a different point in the workflow. I've tried manually re-indexing after the transition has been completed, but no luck.
Code:
import com.atlassian.jira.bc.issue.IssueService.TransitionValidationResult; import com.atlassian.jira.bc.issue.IssueService.UpdateValidationResult; import com.atlassian.jira.component.ComponentAccessor; import com.atlassian.jira.issue.IssueInputParameters; import com.atlassian.jira.issue.MutableIssue; import com.atlassian.jira.issue.index.IssueIndexingService; import com.atlassian.jira.user.ApplicationUser; def fieldManager = ComponentAccessor.getCustomFieldManager(); MutableIssue issue = (MutableIssue) issue; String priority = (String) fieldManager.getCustomFieldObjectByName("Priority").getValue(issue); IssueInputParameters issueInputParameters = ComponentAccessor.getIssueService().newIssueInputParameters(); ApplicationUser user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser(); if (priority.equals("High")) { issueInputParameters.setStatusId("41"); } else if (priority.equals("Medium") || priority.equals("Low")) { issueInputParameters.setStatusId("51"); } else { log.error("Couldn't find valid priority [" + priority + "]"); return; } int actionId = Integer.valueOf(issueInputParameters.getStatusId()); TransitionValidationResult transitionValidationResult = ComponentAccessor.getIssueService().validateTransition(user, issue.getId(), actionId, issueInputParameters); if (transitionValidationResult.isValid()) { ComponentAccessor.getIssueService().transition(user, transitionValidationResult); } else { log.warn(transitionValidationResult.getErrorCollection().getErrorMessages()); }
Post function.png
I've seen this question being asked a few times before over the years, but I couldn't find a working solution.
Community moderators have prevented the ability to post new answers.
Thank you Robbie, it is not working for me. I'm using JIRA version 7.2.1 and sr version 4.3.12. sigh..
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Robbie,
Have you come up with a proper solution other than fast-track script? I'm also looking for it. Thank you
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You should use the fast-track transition script, with conditions and additional code or whatever. It has just about enough smarts to handle this race condition that you are experiencing.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Do you have your own customfield with name "Priority"?
This code is trying to get access to such CustomField, not default priority field.
String priority = (String) fieldManager.getCustomFieldObjectByName("Priority").getValue(issue);
To get acces to default priority field use this
String priority = issue.getPriorityObject().getName()
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Yeah sorry for not making the clear - it's a custom priority field. There's nothing wrong with getting any of the fields, just transitioning the issue.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
1) While writing script post function - you should not use IssueInputParameters to update issue. All data can be update using just MutableIssue.setSomething(). So your code should look like this:
import com.atlassian.jira.component.ComponentAccessor; import com.atlassian.jira.issue.MutableIssue; def fieldManager = ComponentAccessor.getCustomFieldManager(); MutableIssue issue = (MutableIssue) issue; String priority = (String) fieldManager.getCustomFieldObjectByName("Priority").getValue(issue); if (priority.equals("High")) { issue.setStatusId("41"); } else if (priority.equals("Medium") || priority.equals("Low")) { issue.setStatusId("51"); } else { log.error("Couldn't find valid priority [" + priority + "]"); return; }
2) If still does not work - try to delete default "Set issue status to the linked status of the destination workflow step" post function and place your own post dunction to the top
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Community moderators have prevented the ability to post new answers.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.