Jira transition in a workflow

Hemanshu January 4, 2017

Hi, I have a small query.

I have a post function script in a workflow transition according to which if that script executes successfully and an output is gained then transition from A->B goes through successfully. If not, then it stays at A.

Is is possible?

1 answer

0 votes
Corentin Méhat
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.
January 4, 2017

Hello,

you might want to do it with a validator (or a condition), but not with a post-function smile

 

Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 5, 2017

If it's a post-function, it's too late, the transition is almost complete

If it's a validator, then yes, you can return a pass or fail

You do NOT want a condition.  It will be run every time JIRA looks at the issue to see if a user can use it.

Hemanshu January 5, 2017

Hi NIc,

Thanks for the confirmation. How can I implement the same through a validator. I will try to explain the whole scenario:

I have a groovy script, which shoots a curl command to Service Now, and gives an output in my JIRA logs. Based on that output, i want to make sure that the transition goes from A->B or stays at A.

My approach:

I have a custom field which gets populated in my JIRA ticket screen with the result of the grovy script mentioned above. So my requirement is, if custom field gets populated with value X then A->B should take place, if not(e.g. value Y) then transition stays at A.

 

Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 6, 2017

You will need to embed your script in a validator. 

Are you using the script runner add-on?  If not, then you're going to need to write a validator that can run your connection and interpret the result as a pass/fail.

Hemanshu January 8, 2017

Hi Nic, I am using this scriplet in my Validator, but still not working, can you pls suggest:

 

if(finalOutput.contains("[inserted]"))
{
log.debug("Inside incident block");
//def servicenowid = customFieldManager2.getCustomFieldObjectByName("ServiceNow ID");
//log.debug("Service id=$servicenowid")
log.debug("Inside incident block");
issue.setCustomFieldValue(servicenowidfield,finalIncident);
workflowTransitionUtil.setAction (1531);//Transition B
}
else
{
log.debug("Inside Else block");
issue.setCustomFieldValue(servicenowidfield,"Not Created in Service Now");
workflowTransitionUtil.setAction (4);//Transition A
}

 

How can I optimize this script to the above condition?

 

As of now, my script is anyways going to B irrespective of the fact that it catches the else block only.

 

Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 9, 2017

No, hang on, that's not what we were discussing.

You do NOT try to change the target of a transition while it's running.  And there's absolutely no way you should be even thinking of changing an issue in a validator.

A validator should validate something, returning "true" if it's ok, and "false" (with an optional error message) if it fails validation.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events