Scripted Validator

Sravan Duddella April 29, 2022

Hello Team,
Can you please help me with this validator?
We have a field "XYZ" with Yes/No/Unknown options, default value set to Unknown and to push the workflow status to In-progress we need this field's options be either Yes or No. Can you please help ASAP? Thanks!

1 answer

1 accepted

1 vote
Answer accepted
Craig Nodwell
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
April 29, 2022

Hi @Sravan Duddella from the Scriptrunner page
cfValues['My Multi Select']*.value.contains("Some value")

Scriptrunner validators simple-scripted-validators-multi-select 

Here's a more complex example from the Scriptrunner Library
Scriptrunner Library Scripted Validator Multi-Select List 

 

I hope this helps to get you started.
Happy Scripting.

Sravan Duddella April 29, 2022

Hello Craig, Thanks for posting this, so the field is single select but the value can be either Yes or No.

 

using the below argument is throwing errors, looking forward for some help on the right argument to use.  

cfValues['xyz']?.value == "Yes or No"

Craig Nodwell
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
April 29, 2022

Instead of testing for Yes or No why not test what it is not equal to.
re:
cfValues['xyz']?.value != "Unknown"

or to test for the OR
cfValues['Demo']?.value == 'Yes' || cfValues['Demo']?.value == 'No'

Sravan Duddella April 29, 2022

AWESOME! Worked like a charm!!! Thank you so much!!!

Like Craig Nodwell likes this
Craig Nodwell
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
April 29, 2022

Old guy tip.

I hope you used the != to simplify complexity.
Reasoning here is the only value that is invalid is "Unknown" all other values are valid, so therefore you only need to test that the value is not equal to "Unknown".
Testing for the OR requires the system to evaluate the value twice, adding unnecessary complexity to the scripted validator which may be difficult for someone new reading it later on down the line.

Sravan Duddella April 29, 2022

Understood!! Makes complete sense and a lot much easy to implement and read. :)

Like Craig Nodwell likes this

Suggest an answer

Log in or Sign up to answer