It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

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

Kathryn Allison May 05, 2014

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

Kathryn Allison May 08, 2014

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.

JamieA May 08, 2014

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.

Kathryn Allison May 08, 2014

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.

Kathryn Allison May 08, 2014

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?

Kathryn Allison May 08, 2014

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

JamieA May 11, 2014

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

or

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

depending on what you want.

Kathryn Allison May 13, 2014

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

0 votes
Sir Be May 05, 2014

is it A or B and C

or (A or B) and C

or A or (B and C) ?

Kathryn Allison May 05, 2014

A or (B and C)

Sir Be May 05, 2014

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?

Kathryn Allison May 05, 2014

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.

Sir Be May 06, 2014

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
This widget could not be displayed.
This widget could not be displayed.
Community showcase
Published in Jira

Try Jira Cloud for Outlook: Organize your work without leaving your inbox

Hi Atlassian community, My name is Max and I work on the product integration team at Atlassian. I am pleased to announce the early access program for the Jira Cloud add-in for Outlook. This add-in...

794 views 0 12
Read article

Community Events

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

Find an event

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

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you