Missed Team ’24? Catch up on announcements here.

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

Issue status not updating after transition?

Deleted user March 14, 2016

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.

5 answers

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

0 votes
Arif Omer Karacuha
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
January 5, 2017

Thank you Robbie, it is not working for me. I'm using JIRA  version 7.2.1 and sr version 4.3.12. sigh..

0 votes
Deleted user January 5, 2017

@Arif Omer Karacuha As far as I can tell, the transition works now. The code is exactly the same as the question posted above, so I'm assuming the issue must have been non-code related - I can't remember unfortunately.

0 votes
Arif Omer Karacuha
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
January 5, 2017

Hi Robbie,

 

Have you come up with a proper solution other than fast-track script? I'm also looking for it.  Thank you

0 votes
JamieA
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 Leaders.
March 15, 2016

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.

0 votes
Aleks Yenin (Polontech)
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 Leaders.
March 15, 2016

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()
Deleted user March 15, 2016

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.

Aleks Yenin (Polontech)
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 Leaders.
March 15, 2016

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

 

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

TAGS
AUG Leaders

Atlassian Community Events