IssueService.IssueResult transition doesn't modify the status of the issue after a specified transition

Hi Atlassians,

Inside my postfunction, I'm using IssueService.IssueResult transition method in order to transition an issue through workflow.

As specified in the documentation, the issue will be saved and re-indexed and the transition will be made.(https://docs.atlassian.com/jira/6.2.1/com/atlassian/jira/bc/issue/IssueService.html#transition(com.atlassian.crowd.embedded.api.User, com.atlassian.jira.bc.issue.IssueService.TransitionValidationResult) ).

As I understand from that, there is no need to update the issue by code as this method will do it.

In my code, I noticed that the transition is happening (by checking History tab) but the issue is not saved (Status is not modified). I used to put issueManager.updateIssue (kindly ckeck highlighted line in the below code) after it in order to force updating the issue.

My question is: Why implementing IssueService.IssueResult transition is not enough to save the issue after transitioning it?

My code is the following:

TransitionValidationResult transitionValidRes = issueService.validateTransition(authenticationContext.getUser().getDirectoryUser(),issue.getId(),configAction.getId(), issueInputParameters);

log.debug("Current Status of the issue: " + issue.getStatusObject().getName());

log.debug("Action ID: " + configAction.getId());

if (!transitionValidRes.isValid())

{

Iterator<String> ite = transitionValidRes.getErrorCollection().getErrorMessages().iterator();

StringBuilder sb = new StringBuilder();

while (ite.hasNext())

{

sb.append(ite.next());

sb.append("\n");

}

throw new Exception(sb.toString());

}

ErrorCollection transitionErrorCollection = issueService.transition(authenticationContext.getUser().getDirectoryUser(), transitionValidRes).getErrorCollection();

if (transitionErrorCollection.hasAnyErrors())

{

log.error(transitionErrorCollection.toString());

}

else

{

log.debug("New Status of Issue: " + transitionValidRes.getIssue().getStatusObject().getName());

}

issue.setStatusObject(transitionValidRes.getIssue().getStatusObject());

issueManager.updateIssue(authenticationContext.getUser().getDirectoryUser(), issue, EventDispatchOption.ISSUE_UPDATED, false);

Thanks,

Rosy

3 answers

0 vote

Generally, trying to transition an issue while another transition is still executing does not work.

What you've got there would probably work fine in a listener, but I've never seen it work in a post-function (in fact, had jobs cleaning up the mess made by people trying to do this)

I do know it can be done - the script runner and jjupin plugins appear to be doing a transition in a post-function, but it's really not as simple as just trying to kick off a new transition using the issue service (I know at least one of those plugins is effectively starting the transtion after the first one ends),

Thanks Nic.

However, when I checked the code inside Fast Track Script Runner, I noticed that the same method is being used: issueService.transition

WorkFlowUtils.groovy:

public static Issue actionIssue(String additionalScript, MutableIssue theIssue, Integer actionId, User user, Map scriptParams = [:]) {

IssueService issueService = ComponentAccessor.getIssueService()

IssueInputParameters issueInputParameters = new IssueInputParametersImpl([:])

scriptParams.put("issueInputParameters", issueInputParameters)

ConditionUtils.doAdditional(additionalScript, theIssue, scriptParams)

issueInputParameters = scriptParams['issueInputParameters'] as IssueInputParameters

def validationResult = issueService.validateTransition(user, theIssue.id, actionId as Integer, issueInputParameters)

ErrorCollection errorCollection = validationResult.errorCollection

if (errorCollection.hasAnyErrors()) {

// We used to carry on because sometimes these seem spurious. More investigation needed.

log.error (errorCollection)

log.error ("Not attmpting transition")

return null

}

errorCollection = issueService.transition(user, validationResult).errorCollection

if (errorCollection.hasAnyErrors()) {

log.error (errorCollection)

}

else {

log.info ("Transitioned issue $theIssue through action \"$actionId\"")

}

// reload issue

theIssue = ComponentAccessor.getIssueManager().getIssueObject(theIssue.id)

Status finalStatus = theIssue.statusObject

log.debug "Final status: ${finalStatus.getName()} (${finalStatus.id})"

theIssue

}

Thanks,

Rosy

I have the same question. I have been struggling to get this to work, without success, as a listener for a couple of days now sad

Suggest an answer

Log in or Sign up to answer
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Julia Dillon
Posted Apr 17, 2018 in Jira

Tell us how your team runs on Jira!

Hey Atlassian Community! Today we are launching a bunch of customer stories about the amazing work teams, like Dropbox and Twilio, are doing with Jira. You can check out the stories here. The thi...

792 views 2 19
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you