Simple script validator - if multi select field has a value and a select field cannot be empty

JIRA Server 6.3.10  ScriptRunner 4.1.3.15

We wanted to do a simple script validation for the following

1) if the value of a multi-select field FieldMS is 'Yes' then a single select field FieldSS cannot be empty

2)  if the value of a multi-select field FieldMS is 'Yes' then another multi select field FieldOMS cannot be empty

We tried 

for point 1 - !cfValues['FieldMS']*.value.contains("Yes") || cfValues['FieldSS']
for point 2 - !cfValues['FieldMS']*.value.contains("Yes") || cfValues['FieldOMS']

It works if value 'Yes' is chosen and dependent field is empty but unfortunately even if the FieldMS is empty validations are triggered which should not be the case.

Tried with 

!('Yes' in cfValues['FieldMS']*.value) || cfValues['FieldSS'] but not working.

Any ideas?

 

2 answers

Hi Ganesh,

if (cfValues['FieldMS']*.value == ["Yes"] && ! cfValues['FieldSS']?.value)
    return false

return true

So the above validator means:

If the FieldMS value IS Yes then if the FieldSS has no value selected then fail. In any other case, for example if FieldMS CONTAINS Yes and Maybe values and the FieldSS has no value selected then pass. 

regards, Thanos

0 vote
Peter Bengov Community Champion Jan 18, 2017

Hi Ganesh, 

Is FieldMS mandatory for this step? Maybe a check for a null value is in order. 

Also, try to use something like !(['Yes'].contains(cfValues['FieldMS'].value))

Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published Thursday in Jira

5 ways you can make the most of Jira Software and Bitbucket Cloud

As part of the Bitbucket product team I'm always interested in better understanding what kind of impact the use of our tools have on the way you work. In a recent study we conducted of software devel...

75 views 0 5
Read article

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