Script Runner Simple Scripted Validator does not work as expected

We have a custom field "Field Issue" (a checkbox), and another custom field "Cause Analysis" (multi line text).

Now I want to make sure that when a fiel issue is resolved, a cause analysis must be documented.

So I created a validator for the resolve issue workflow step:

cfValues['Field Issue']?.getValue() == null || cfValues['Cause Analysis']

System Behaviour:

  1. When "Field Issue" is checked and "Cause Analysis" is empty, the validation fails (OK)
  2. When "Field Issue" is checked and "Cause Analysis" contains text, the validation fails (not OK)
  3. When "Field Issue" is not checked and "Cause Analysis" contains text, the validation passes (OK)
  4. When "Field Issue" is not checked and "Cause Analysis" is empty, the validation passes (OK)

Any help is highly appreciated!

2 answers

try replace
cfValues['Cause Analysis']

with

(cfValues['Cause Analysis']!= null && cfValues['Cause Analysis'].toString().trim().length()>0)

for checking None/Empty spaces inputs into the 'Cause Analysis' field

Thank you for the suggstion, Eason. Unfortunately, it didn't work. The problem seems to be the || combination of the two checks. Because if I separate them in two different validators (one for Field Issue and the other for Cause Analysis), the system applies the expected logic, even with the short version cfValue['Cause Analysis'].

 

I just found the expression that solved my problem:

!cfValues['Field Issue'] || cfValues['Cause Analysis']

Helpful to find and verifying it was the admin->built-in scripts->condition tester, where it is far easier and quicker to test different "solutions" until you find the right one.

Suggest an answer

Log in or Sign up to answer
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Julia Dillon
Posted Apr 17, 2018 in Jira

Tell us how your team runs on Jira!

Hey Atlassian Community! Today we are launching a bunch of customer stories about the amazing work teams, like Dropbox and Twilio, are doing with Jira. You can check out the stories here. The thi...

767 views 2 19
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