Simple Scripted Validator to prevent single value from a Select List

Ashton Treadway January 16, 2013

Throwing myself on the mercy of the boards, because I am not having any luck getting this to work on my own:

I have several select lists with options "Please select a value", "Yes", and "No".

I want to run a simple scripted validator against these select lists that prohibits the transition if the selected value is "Please select a value".

What syntax am I looking for?

I've tried

cfValues[11083] != 'Please select a value'

! cfValues[11083]*.value.contains('Please select a value')

And variations thereof, which do not seem to work. And I have to assume this is because I am Doing It Wrong.

So, help.

Again, I want to permit the transition ONLY if the selected value is anything other than "Please select a value".

EDIT:

Additional complication is that the end customer does not want "None" as a value in the list.

2 answers

1 accepted

1 vote
Answer accepted
JamieA
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 22, 2013

Assuming it's a single select I think you want something like:

cfValues['Name of custom field'].value != 'Please select a value'

cfValues is always indexed by field name, not field ID. So what you you see in the web UI.
Use *.value.contains(...) when it's a multiselect.
But, adding
log.warn (cfValues['Name of custom field'])

before the condition will print it out in the log, which will give you all the info you need.
JamieA
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.
August 6, 2014

That's why I always say to use the safe navigation operator in this case:

cfValues['Name of custom field']?.value == null

Jessy Li August 6, 2014

and for checking if a select field is null ,

cfValues['Name of custom field'].value == null can't work

but use cfValues['Name of custom field'] == null

Take me 2 days to figure it out.

Jessy Li August 6, 2014

Jamie, Thank you for your quick responding. You are such a nice guy.

JamieA
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.
August 6, 2014

Not really, but thanks ;-)

0 votes
Renjith Pillai
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 16, 2013

Why don't you use the validator "Field Required" from JIRA Suite Utilities and get rid of the option "Please select a value" (move that to your field description)

https://confluence.atlassian.com/display/JIRA/Using+Validators+to+Make+Custom+Fields+Required+on+Transition+Screens

Ashton Treadway January 22, 2013

Human behavior is to go with the defaults; we don't want to skew metrics, so we want to force the user to choose an actual value.

Going with "field required" defaults the field value to the first entry in the list, which is not desired.

Suggest an answer

Log in or Sign up to answer