Simple Scripted Validator help needed for my workflow

Hi

I currently have a workflow in design, which requires some fields and responses on the field selection to happen.

Here is the workflow selection as it is currently at:

DEMO required: (drop down menu)

Option 1: Yes
Option 2: No

I already have a Condition to the DEMO field:
The field Demo will have to be not equal to value 'None'. Compared as String.

I require two Simple Scripted Validators to check on each of the values.

IF Option 1 (Yes) is selected, then another field is mandatory to be filled in;
In this case A User Picker (Only certain users has been marked as usable)

cfValues['Demo'] == 'Yes' AND cfValues['Demo Attended by'] == 'NULL'

THEN Error Message: Please select user from the list

IF Option 2 (No) is selected, then another field is mandatory to be filled in;
In this case the required field is a Drop Down menu which can't be NONE which is the default value

cfValues['Demo'] == 'No' AND cfValues['Reason for No Demo'] == 'None'

THEN Error message: "Please select a reason for this request from the drop down menu"

Now my question is, will the above work. This is from a copy of a current Production Workflow which has been requested to be updated, so I don't have a test environment to see whether the above scripts will work as requested. Something else I've noticed is the following

Error message that will be provided to the user if the condition is not true

I need an error message for when the value I have given is true

The above scripts must validate that if the one option is selected another must be true for it to continue. For me they look right, but I need some more eyes on the transition to help me out.

1 answer

1 accepted

5 votes
Henning Tietgens Community Champion Nov 12, 2013

If the field is a select field it will not work. You have to use cfValues['Demo'].getValue() to get the String value of the selected option.

If you surround your condition C with a !(C) you get the error message if C is true.

You should really get a test system (even a test project in the live system is better than nothing). Trying scripts on the production system could be really dangerous, because on wrong statement could crash the system or slow it down to an unusable state.

Hi Henning

Thanks for your response. I'm new to the "code" side of the workflow, so please excuse my next question.

From what you have said above, I gather the following changes needs to be applied to the scripted validator:

cfValues['Demo'].getValue() == 'Yes' AND cfValues['Demo Attended by'] == 'NULL'

cfValues['Demo'].getValue() == 'No' AND cfValues['Reason for No Demo'].getValue() == 'None'

Regarding your comment about condition (C):

THEN Error message:

!(Please select a reason for this request from the drop down menu)

or should it be placed around the code above:

!(cfValues['Demo'].getValue() == 'Yes' AND cfValues['Demo Attended by'] == 'NULL')

Henning Tietgens Community Champion Nov 12, 2013

The !() must be place around the code. It stands for NOT().

You cannot use "AND" in Groovy, it's &&.

"None" is not a real value, it's no value (null). Null is false in Groovy truth (see here).

So the validators should be

!(cfValues['Demo'].getValue() == 'Yes' && !cfValues['Demo Attended by'])

!(cfValues['Demo'].getValue() == 'No' && !cfValues['Reason for No Demo'])

Thanks for the feedback. Will be implementing a duplicate project to test the workflow on.

Much appreciated

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 Tuesday 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...

174 views 1 17
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