Script Runner - Validating two fields using Simple Scripted Validator

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

2 votes
cfValues['Select List'].value != 'Yes' || cfValues['Text Line']

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

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

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

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

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.

Suggest an answer

Log in or Join to answer
Community showcase
Sarah Schuster
Posted Jan 29, 2018 in Jira

What are common themes you've seen across successful & failed Jira Software implementations?

Hey everyone! My name is Sarah Schuster, and I'm a Customer Success Manager in Atlassian specializing in Jira Software Cloud. Over the next few weeks I will be posting discussion topics (8 total) to ...

2,853 views 12 18
Join discussion

Atlassian User Groups

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

Find a group

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

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot