Issue Transitioning oddity

ChristopherG October 16, 2014

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
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.
October 16, 2014

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.

0 votes
ChristopherG October 21, 2014

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

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.
October 22, 2014

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
TAGS
AUG Leaders

Atlassian Community Events