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

Rich Scire February 23, 2016

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

0 votes
Answer accepted
Vasiliy Zverev
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.
February 23, 2016

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

 

Rich Scire February 24, 2016

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
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.
February 24, 2016

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

Rich Scire February 26, 2016

Thanks!

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.
February 26, 2016

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.

3 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.
February 24, 2016

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