Issue Transitioning oddity

I am trying to transition issues through the workflow using the code below as a workflow POST function.  When the script executes it appears to run fine with no errors.  The workflow buttons on the top are updated with the correct destination transitions but, the status of the workflow shows the original destination and not the correct one it transitioned to.

Any Assistance would be appreciated.

Thanks!

 

log = Category.getInstance("com.verizon.jira.groovy")

MutableIssue issue = issue

Status initialStatus = issue.statusObject

log.warn("Starting ARS_CheckForDomestic.groovy (ID: " + issue.key.toString() + ")");
def indexManager = ComponentAccessor.getIssueIndexManager()

CustomFieldManager customFieldManager = ComponentManager.getInstance().getCustomFieldManager();

CustomField cfLocation =  customFieldManager.getCustomFieldObjectByName( "Location" );
String cfvLocation = issue.getCustomFieldValue(cfLocation);

if (cfvLocation == "Domestic (USA, CA)") {
    User user = ComponentManager.getInstance().getUserUtil().getUser('system');

    IssueService issueService = ComponentManager.getComponentInstanceOfType(IssueService.class)
    IssueInputParameters issueInputParameters = new IssueInputParametersImpl([:])
    //issueInputParameters.setAssigneeId("system");

    issueInputParameters.setStatusId("Pending Approval")
    IssueService.TransitionValidationResult validationResult = issueService.validateTransition(user, issue.id, 91 as Integer, issueInputParameters)
    def errorCollection = validationResult.errorCollection
    log.debug(errorCollection)
    if (! errorCollection.hasAnyErrors()) {
        issueService.transition(user, validationResult)
    }
    else {
        log.warn("Error transitioning issue.")
    }

    }

log.warn("Completed ARS_CheckForDomestic.groovy (ID: " + issue.key.toString() + ")");

2 answers

1 vote

This is not at all straightforward. The database commit is not done until the first transition finishes, and you end up with a mishmash of two different states with your approach.

You should try the built-in fast-track script. Everything above your "if" can go in the Condition, the issueInputParameters stuff you pass in the "additional code" section.

I started out with a listener with the following:

 

Project: Target Project

Events:  Issue Updated

Condition:  issue.status == 'Pending Missing VZID Approval' && cfValues['Location'] == 'Domestic (USA, CA)'

Action:  Target Transition.

 

This resulted in no transition.  I went so far as to remove the Condition and still was not getting transitioned.

Thoughts?

 

Thanks,

Chris

Your condition is not right, but what is this for, fast-track? Have you decided to use the built-in script? The first part should be: issue.statusObject.name == ... If Location is a select list you should use: cfValues['Location']?.value == "Domestic ..."

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
Bridget Sauer
Published Thursday in Marketplace Apps

Calling all developers––You're invited to Atlas Camp 2018

 Atlas Camp   is our developer event which will take place in Barcelona, Spain  from the 6th -7th of   September . This is a great opportunity to meet other developers and get n...

348 views 0 6
Read article

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