The Atlassian Community Forums are currently in read-only mode. We will be relaunching on a new platform on September 22 (read more here). We apologize for the extended downtime. For concerns or questions, please email communitymanagers@atlassian.com. See you on the other side, on the new Atlassian Community Forums! :)

×

Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Script Runner - Validating two fields using Simple Scripted Validator

Reimar Robles
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
March 5, 2015

Hi,

Trying to validate two custom fields (select list and text line - multi) but can't get it to work and does not seem to validate properly.  It either parses the first condition or not at all.

The goal of the validation is to display an error message if user selects 'Yes' but leaves the comment field blank/null.

I've tried different variations of this condition and switched the conditions around but to no avail.  

cfValues['Select List'].value.contains('Yes') && cfValues['Text Line']?.value == null

 

Variations

#1

if (cfValues['Select List'].value.contains('Yes'))
{
        cfValues['Text Line']?.value == null
}

#2

if (cfValues['Select List'].value.contains('Yes'))
        cfValues['Text Line']?.value == null

#3

cfValues['Select List'] == 'Yes' && cfValues['Text Line'].value == null

and others.

I've also added the following before the condition to check the logs to see if the values of the custom fields are as expected and they are...

log.warn (cfValues['Select List'])
log.warn (cfValues['Text Line'])

Appreciate any help!

2 answers

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

2 votes
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 Champions.
March 5, 2015
cfValues['Select List'].value != 'Yes' || cfValues['Text Line']

should work if it really is a single select and a text field.

rikkin patel
August 25, 2015

What if it's a multi select and a text field? what would the condition be then?

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 Champions.
August 25, 2015

'Yes' in cfValues['Select List']*.value || cfValues['Text Line']

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 Champions.
August 25, 2015

!('Yes' in cfValues['Select List']*.value) || cfValues['Text Line']

0 votes
Mamta Bodhale
Contributor
December 11, 2015

Is there an "OR" parameter to this? i.e. The value of the custom field should be A or B (instead of comparing to a single value) for the validation to be true.