Script Runner: auto transition a task after validating custom field value is not empty

Avril Bower
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 27, 2016

Hello, 

Here's my issue. I have a status 'Waiting for training date confirmation', within the status I have 5 transitions: Training Date confirmed, PDM approval, TDU approval, EU approval and Intl. approval.

status view.jpg

The approval transitions set the date value of a corresponding custom field. What I would like to do is automatically fire the transition 'Training date confirmed' to move the task to the next status after the other four transitions have been fired or validate that their corresponding fields are not empty. 

transition post function.jpg

I am using the scripted 'Fast-Track transition an issue' postfunction

Condition: 

issue.issueTypeObject.name == 'Feature Rollout'

Action: Training date confirmed

Additional Code: 

(!cfValues['Training date PDM approval'].getValue().equals('') && !cfValues['Training date TDU approval'].getValue().equals('') && !cfValues['Training date EU approval'].getValue().equals('') && !cfValues['Training date Intl. approval'].getValue().equals(''))

I believe I need to def the custom fields but I'm not quite sure. Could you please point me in the right direction?

Postfunction.jpg

Also, I assume that I only need to place this post-function on the 'Training date confirmed' transition and not the others. Would that be correct?

 

 

Thank you!

1 answer

0 votes
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.
January 27, 2016

I think that you need to place a condition that all requared dates are not empty into condition section. And you do not need any code into additional code.

Avril Bower
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 1, 2016

Thanks Vasiliy,

I've removed the script from 'Additional Code' and moved it up to 'Condition' as suggested. I've also switched up the code here to CF value !=  null from everything I am reading this should have worked well.

New Code:

cfValues['Training date PDM approval']?.getValue() != null
&& cfValues['Training date TDU approval']?.getValue() != null
&& cfValues['Training date EU approval']?.getValue() != null &&
cfValues['Training date Intl. approval']?.getValue() != null

However, I am getting the following in the logs:

2016-02-01 13:14:32,449 ... ERROR ... /secure/WorkflowUIDispatcher.jspa [canned.jira.utils.ConditionUtils] Condition failed on issue: ABT-21, built-in script:com.onresolve.scriptrunner.canned.jira.workflow.postfunctions.FasttrackTransition

groovy.lang.MissingMethodException: No signature of method: java.lang.String.getValue() is applicable for argument types: () values: []

Possible solutions: getClass(), getAt(groovy.lang.IntRange), getAt(groovy.lang.Range), getAt(groovy.lang.EmptyRange), getAt(java.lang.String), getAt(groovy.lang.IntRange)

               at Script104.run(Script104.groovy:1)

2016-02-01 13:14:32,451... ERROR ... /secure/WorkflowUIDispatcher.jspa [canned.jira.utils.ConditionUtils] Script follows:

cfValues['Training date PDM approval']?.getValue() != null && cfValues['Training date TDU approval']?.getValue() != null && cfValues['Training date EU approval']?.getValue() != null && cfValues['Training date Intl. approval']?.getValue() != null

None of the possible solutions make sense. I've researched the error as well but still can't figure out where I am going wrong.

Maud Schlich February 4, 2016

Hello Avril,

so your current Status is "'Waiting for training date confirmation'.

When you are transitioning to PDM approval you should check für the other three approvals and then fast Transition to Waiting for WebEx .

I'd write a ScriptRunner Script something along the line

 

 

def bool_all_approved// check Approvaldef cf_PDMapproval = customFieldManager.getCustomFieldObjects(sourceIssue).find {it.name == ''Training date PDM approval'}def cf_TDUapproval  = customFieldManager.getCustomFieldObjects(sourceIssue).find {it.name == ''Training date TDU approval'}def cf_EUapproval = customFieldManager.getCustomFieldObjects(sourceIssue).find {it.name == ''Training date EU approval'}def cf_INTapproval  = customFieldManager.getCustomFieldObjects(sourceIssue).find {it.name == ''Training date Intl. approval'}bool_all_approved = ( cf_PDMapproval != null &&  cf_TDUapproval != null &&  cf_EUapproval != null &&  cf_INTapproval != null )

 

Hope this helps, if I find the time, I'll try to improve this and code it in a test environment next week - if you can wait that long.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events