[ScriptRunner]' code validator for transition.

Rajiv Ranjan November 25, 2019

I am using a simple Simple scripted validator option to validate the Acceptance Criteria field mandatory over a workflow transition however the code is not working in some combination of operators.

Not working code

{code}

issue.projectObject.key == 'AAAA' || cfValues['Acceptance Criteria'] == null

OR

issue.projectObject.key == 'AAAA' && cfValues['Acceptance Criteria'] == null

OR

issue.projectObject.key == ['AAAA', 'BBBB'] && cfValues['Acceptance Criteria'] == null

{code}

Also not able to use validator code for multiple projects that mean the same code is added multiple time for diffrent projects to validate the same field in the same transaction. 

 

Working code

{code}

issue.projectObject.key != 'AAAA' && cfValues['Acceptance Criteria'] != null

{code}

How come "!=" operator working perfect for here.

1 answer

1 accepted

0 votes
Answer accepted
Antoine Berry
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
November 26, 2019

Hi @Rajiv Ranjan ,

Not sure exactly which condition you are trying to achieve, but this should work : 

issue.projectObject.key in ['AAAA', 'BBBB'] && cfValues['Acceptance Criteria'] == null

Antoine

Rajiv Ranjan November 26, 2019

@Antoine Berry

Thank you for your response but this code not working

issue.projectObject.key in ['AAAA', 'BBBB'] && cfValues['Acceptance Criteria'] == null

 

The below code is working for an individual project but it' confusing because using "!=" operator. Attached the working code screenshot

issue.projectObject.key != 'AAAA' || cfValues['Acceptance Criteria'] != nullimage.png
Antoine Berry
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
November 26, 2019

@Rajiv Ranjan , 

I am not sure to understand your need, could you please specify your requirement so I can answer as best as I can ?

Thanks.

Rajiv Ranjan November 26, 2019

@Antoine Berry ,

I am trying to achieve the Acceptance Criteria field mandatory over a workflow transition (from In Definition to Open). To achieve that I user Simple scripted validator option over the transition validator however it's not working as expected.

Note: Upon transition from "In Definition" to "Open", in case users didn't fill in the field, they will get an error message and will be required to click “Edit” and enter the acceptance criteria in order to proceed

issue.projectObject.key in ['AAAA', 'BBBB'] && cfValues['Acceptance Criteria'] == null
Antoine Berry
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
November 26, 2019

So if you want the validator to check if the Acceptance Criteria is not empty, and to execute only for projet AAAA and BBBB, you would need : 

issue.projectObject.key in ['AAAA', 'BBBB'] && cfValues['Acceptance Criteria'] != null

Antoine

Like Rajiv Ranjan likes this
Rajiv Ranjan November 27, 2019

Hi @Antoine Berry 

Yes, the code is working.

Also learned it doesn't matter how we using operators but it should script returns a  False value then the transition will be blocked with the error message.

Below both codes are working.

(!(issue.projectObject.key in ['AAAA', 'BBBB', 'CCCC'])) || cfValues['Acceptance Criteria'] != null

issue.projectObject.key in ['AAAA', 'BBBB', 'CCCC'] && cfValues['Acceptance Criteria'] != null

Thanks for your time and assistance. 

Like Antoine Berry likes this

Suggest an answer

Log in or Sign up to answer