Scrit Runner listener can't change status on Issue Create event

I have a SR custom listener that is fired when an issue in a particular project is created. The script changes some fields then tried to transition the issue  from the Open status to the Assigned status using the Assigned transition. When trying this the script throws the error:

It seems that you have tried to perform a workflow operation (Assigned) that is not valid for the current state of this issue (EPROREQ-1139). However, the transition is valid as I can make that very transition manually. In addition if I change the firing criteria to add issue updated the modify a field in the issue, the transition works correctly.

This indicates to me that there is a problem with when the script is triggered and not the script itself. The relevant code is:

void PerformTransition(actionId, log, scriptName) {
    String methodName = 'PerformTransition'
    log.debug(scriptName + ":" + methodName + ": actionId: " + actionId + "; Status: " + issue.getStatusObject().getSimpleStatus().getName());

    IssueService issueService = ComponentAccessor.getIssueService()

    // Set the action parameters
    IssueInputParameters issueInputParameters = new IssueInputParametersImpl([:])
    issueInputParameters.setComment("${scriptName}: Changed status to Assigned.")
 
    // Get the currently logged in users
    ApplicationUser applicationUser = ComponentAccessor.getJiraAuthenticationContext().getUser()
    User user = ApplicationUsers.toDirectoryUser(applicationUser);

    // Test the transition and see if it generates errors
    IssueService.TransitionValidationResult validationResult = issueService.validateTransition(user, issue.id, actionId, issueInputParameters)
    def errorCollection = validationResult.errorCollection

    if (!errorCollection.hasAnyErrors()) {
        IssueService.IssueResult issueResult = issueService.transition(user, validationResult)
    } else {
        log.debug(scriptName + ":" + methodName + ": Got transition errors");
        log.debug("Validation Errors: " + errorCollection)
    }
    String finalStatus = issue.getStatusObject().getSimpleStatus().getName()
    log.debug(scriptName + ":" + methodName + ": finalStatus: " + finalStatus);
}

Here is the log output when fired in issue creation:

Entering ESM Assignment (1.0.0); Field Changed; Segment/Region Alignment
ESM Assignment:getCustomFieldValue: Field: Segment/Region Alignment
ESM Assignment:getCustomFieldValue: value: Manufacturing - Brian Long
ESM Assignment: xjxc250
ESM Assignment: New assignee login: xjxc250; New assignee name: Jennifer Cavucci
ESM Assignment:PerformTransition: actionId: 21; Status: Open
ESM Assignment:PerformTransition: Got transition errors
Validation Errors: Errors: {}

Error Messages: [It seems that you have tried to perform a workflow operation (Assigned) that is not valid for the current state of this issue (EPROREQ-1139). The likely cause is that somebody has changed the issue recently, please look at the issue history for details.]

Here is the log output when the script was fired when the issue was updated

ESM Assignment:getCustomFieldValue: Field: Segment/Region Alignment

ESM Assignment:getCustomFieldValue: value: Manufacturing - Brian Long

ESM Assignment: xjxc250

ESM Assignment: New assignee login: xjxc250; New assignee name: Jennifer Cavucci

ESM Assignment:PerformTransition: actionId: 21; Status: Open

ESM Assignment:PerformTransition: finalStatus: Open

 

 Interestingly, I see that both logs show "ESM Assignment:PerformTransition: finalStatus: Open" which is logged after the completion of the "issueService.transition" call. Obviously, there is some processing after the script exits that causes the state transition to be stored in the DB.

Any help determining why the transition is not taking effect after the Issue Create event would be much appreciated.

2 answers

1 accepted

Accepted Answer
0 votes
Vasiliy Zverev Community Champion Feb 23, 2016

It seems that user who do this transition is not allowed to do it. Check that this user has respective permission

 

I do have access since I can make the transition manually. Second, it works correctly when the event is update but not if it is create.

Vasiliy Zverev Community Champion Feb 24, 2016

More one option: any updates should be done after store an issue to a database. See postfunction list.

You can use com.atlassian.jira.bc.issue.IssueService#validateTransition(com.atlassian.jira.user.ApplicationUser, java.lang.Long, int, com.atlassian.jira.issue.IssueInputParameters, com.atlassian.jira.workflow.TransitionOptions), TransitionOptions has flags to skip permissions and conditions etc.

2 votes

You should use the Fast-track transition script... there are a load of corner cases and this scripts handles them.

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted Sep 18, 2018 in Jira

What modern development practices are at the heart of how your team delivers software?

Hey Community mates! Claire here from the Software Product Marketing team. We all know software development changes rapidly, and it's often tough to keep up. But from our research, we've found the h...

21,415 views 2 7
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