Simple Scripted Validator triggers error, but keeps triggering even after field is filled out

I have a simple scripted validator I want to validate whether a field it filled out based on another field's value:

cfValues['Implementation Method']?.getValue() == "Premise" || cfValues['Implementation Method']?.getValue() != "Premise" && issue.projectObject.key != "ELM"

When "Premise" is the value in the custom field it lets me move the workflow. When "Premise" is not the value, it throws a validator against Due Date (as intended), but keep throwing it even after I fill out Due Date field.

Also, I need this to be expanded to 3 other projects, and wasn't positive on how to do that.

Thanks in advanced.

2 answers

1 accepted

There's nothing wrong with the script. Even testing against a simple line I'm having the same issue: the script throws the validation error against the Due Date field, but keeps throwing it even after I fill out due date. If I use a different custom field, it works how I expect it to. Both custom fields are of Select List type.

I don't understand where Due Date comes in to this. Can you attach a screenshot?

If you've put the error against Due Date it will go against that field, but if that field is not in the validator it has nothing to do with whether the condition passes.

Is your objective to make the due date required depending on some other conditions?

If so you should do

cfValues['Due Date'] || ! (your current clause)

that is, the due date is required unless your current clause is true.

Due Date is not a custom field, but a system field, would cfvalues['Due Date'] still work for system field? I did put it against the field without the field in the validator, and I have done so in the past and it worked fine. The current one also works the same way with a different custom field then I am using currently.

Your suggestion works on a custom date field, but it doesn't work for Due Date because Due Date is a system field. How can I leverage the system date field in the script?

Ok, I figured it out, I just needed to replace cfvalues['Due Date'] with issue.getDueDate() != null and it seems to work.

Is there any way to adjust the issue.projectObject.key != "ABC" to multiple project keys or do I need to use || and brackets for each different key? I need to to do it for 4 projects

issue.projectObject.key in ["ABC", "DEF"]

or

! (issue.projectObject.key in ["ABC", "DEF"])

depending on what you want.

I actually needed to leverage both. Thanks for your help :)

This widget could not be displayed.

is it A or B and C

or (A or B) and C

or A or (B and C) ?

Does the adding of the brackets to the code make any difference? :s
(Never know)

To 'debug': add some println's

println cfValues['Implementation Method']?.getValue()

println cfValues['Implementation Method']?.getValue() == "Premise"

....

And check your log, maybe it helps?

No, it didn't. The validator is passing the erroring properly, but once I fill out the field being validated against, it still throws the error message. If I replace Implementation Method with a different custom field/value it works correctly.

To be honest: I'm not an expert (more a noob) in this.

Just having some experience with it, cause I had to do something and also had to experiment ...

Suggestions:

-Correct cf name?

-Try using the cf-id?

-Test with the println ?

-.....

Jamie Echlin is an expert in this mather, try adding tags with his name, so he will notice this question? :)

Suggest an answer

Log in or Sign up to answer
Atlassian Summit 2018

Meet the community IRL

Atlassian Summit is an excellent opportunity for in-person support, training, and networking.

Learn more
Community showcase
Posted Wednesday in New to Jira

Are you planning to trial, or are currently trialling Jira Software? - We want to talk to you!

Hello! I'm Rayen, a product manager at Atlassian. My team and I are working hard to improve the trial experience for Jira Software Cloud. We are interested in   talking to 20 people planning t...

155 views 2 0
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