It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

[ScriptRunner]' code validator for transition. Edited

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 Nov 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

@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 Nov 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.

@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 Nov 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

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
TAGS

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you