Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

JMWE: Unable to combine OR operator in validator

Paul Alexander
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 22, 2022

I have this JMWE script functional as a validator on a transition in a workflow. If the Tempo Account field matches this value then an error is thrown on the transition modal to ask the user to choose a different account. It works good by assuring that those issues with Account 123 are unable to pass.

!!issue.customfield_12440 && issue.customfield_12440.value != "Account 123"

I need to test for Account 123 or Account 789 in the Account field and throw the same error if either is false but I'm unable to combine this with a logical OR "||". I've tried various syntax, but the validation is always true for some reason so it lets issues, for example, with Account 123 or Account 789 through without blocking.

!!issue.customfield_12440 && issue.customfield_12440.value != "Account 123" || !!issue.customfield_12440 && issue.customfield_12440.value != "Account 789"

 

1 answer

1 accepted

1 vote
Answer accepted
David Fischer
Community Champion
November 22, 2022

Hi @Paul Alexander 

If I understand correctly, you really want an "and", not an or. Because you want the value to be different from Account 123 and to be different from Account 789

A shorter version of this condition is:

!!issue.fields.customfield_12440 && !["Account 123","Account 789"].includes(issue.fields.customfield_12440.value)
Paul Alexander
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 22, 2022

Hi David. This does not work since it throws the error for an issue with Account ABC when it should allow it through.

I need to invalidate either Account 123 OR Account 789 and display the error on the transition's modal, in my case, the Close Transition. If the issue's account equals one of these two values, I need it to block.

Examples:

  • If the issue has Account 123, throw the error
  • If the issue has Account 789, throw the error
  • If the issue has any other value let it through
Paul Alexander
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 22, 2022

I am using the 'build your own script' validator if that matters...

David Fischer
Community Champion
November 22, 2022

Sorry, I overlooked the fact that this is a script for a workflow validator. Jira Cloud Conditions and Validators use Atlassian's Jira Expressions language and thus differ from Nunjucks that is used in JMWE post-functions. In particular, fields are accessed without ".fields". Therefore, the expression should be:

!!issue.customfield_12440 && !["Account 123","Account 789"].includes(issue.customfield_12440.value)
Paul Alexander
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 22, 2022

This works. That's good to know, David. As usual, I very much appreciate you and your product ;-).

-Paul

Suggest an answer

Log in or Sign up to answer