Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Next challenges

Recent achievements

  • Global
  • Personal

Recognition

  • Give kudos
  • Received
  • Given

Leaderboard

  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

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

Validators Checkboxes JMWE

I want create validation  with condition :

Custom field - Checkboxes : Deployment 

Options :

- DR

- DC

- None

the question is how to make pop up error if user choose DR&None / DC&None/ DR&DC&None 

I try used 

(issue.customfield_12308.some (it => it.value == "None"))

Its work  in Test Jira Expression, but its not work after publish the workflow

3 answers

1 accepted

0 votes
Answer accepted

Hi David,

what I want is pop up error if user choose

DR&None

DC&None

DR&DC&None 

Empty

 

and the status can be contiune if user choice

DR

DC

DC&DR

None

 

What the meaning "!!" / "!" ? 

!issue.customfield_12308.some(it => it.value == "None"
!!issue.customfield_12308 

! means "not", and thus "!!" means "not not" which really means "is true". "!!" is needed to transform any "truthy" value into a real "true" value (because Jira expressions support "truthy" and "falsy" values during the evaluation of the expression, but Conditions and Validators only support "true" or "false" as the returned value)

If you need to enforce selecting at least one value, then try this:

!!issue.customfield_12308 && issue.customfield_12308.length > 0 &&
(!issue.customfield_12308.some(it => it.value == "None") || issue.customfield_12308.length == 1)
Like Tyas Iglecias likes this

Its Work thanks David :D

Glad I finally found this answer. It would be great if this was in the KB for JMWE Cloud.

Also, do you know why the include function doesn't work like I would expect it to? The syntax of the some function always confuses me.

Thanks!

Hi Darry,

Because it is Jira expressions (used in Conditions and Validators of Cloud) and not Nunjucks (used in post-functions). See here for information on Jira expressions.

Regards,

Radhika

Weird, because that link says:

List literals
Lists can not only be obtained from context objects but also created manually. For example, to check if the issue type is either a Bug or Task, create a list with these two types and use the includes() method to test if the actual value is one of the two listed:

['Bug', 'Task'].includes(issue.issueType.name)

And on another page:

 

  • some(Any => Boolean): Checks if the list contains at least one element that satisfies the given predicate (Boolean).
  • includes(Any): Checks if the given argument is stored in the list (Boolean).

I think maybe I'm not understanding what the argument for includes() should look like. From the first example, I guess something like this might work?

['None'].includes(issue.customfield_12308.value)

Guess I'll play around with it tomorrow.

Hi Darry,

My bad. My statement was incorrect. As mentioned in the document, using include you could check if the actual value is one of the values listed. Whereas some is a closure that checks if the list contains at least one element that satisfies the given predicate. So in the above example, in which you want to check that "None" option is selected, some should be used to check for the value of the option, which you cannot do using include

Regards,

Radhika

I guess I still don't understand the difference between includes and some.

It seems like includes should work the same way some is currently working. As the documentation says: 

  • includes(Any): Checks if the given argument is stored in the list (Boolean).

I tried the different syntax ['None'].includes(issue.customfield_12308.value), but didn't have any success.

What is the custom field type of customfield_12308? Is it a single-select field or a multi-valued field (e.g. Checkboxes)?

Also, is "None" (in your case) an actual "Option" of the custom field, or do you mean it as "no value selected"?

Hi David - it's a multi-valued Checkbox field. "None" is an actual option.

Like Tyas Iglecias likes this

Then issue.customfield_12308.value is invalid, since issue.customfield_12308 returns a List of values, as shown on the Issue Fields help tab below the editor. Please use that help tab to insert the correct Jira expression for your custom field. 

If I wanted to use includes, what would the correct syntax be?

I think I tried this, initially:

issue.customfield_12308.includes('None')

And it worked for the positive case (when None was checked), but I was trying to find the dispositive (?) (None not checked) and was having problems with I think this:

!issue.customfield_12308.includes('None')

You cannot use include with multi-valued fields. The correct syntax to check multi-valued fields such as Checkboxes is shown on the Issue Fields help tab:

image.png

In your case, you'd want:

!!issue.customfield_12308 && issue.customfield_12308.some(it => it.value == "None")

And the opposite test would be:

!issue.customfield_12308 || !issue.customfield_12308.some(it => it.value == "None") 

Sorry, I'm being dense, but I think I'm getting it (slowly).

So just for clarification, is the reason includes won't work because multi-value fields are not actually List literals (arrays), but rather something like a Dict (key-value pairs), hence the requirement to do the iterations with some?

Not exactly. It's because multi-valued fields (multi-select and checkboxes, version pickers, user pickers, etc.) return a List of objects, not string literals. For example, checkboxes return a List of "Option" objects (in the form of a JavaScript hash, or JSON object, however you want to look at it) that contain 3 properties: id, value and "self" (a URL):

[
  {
    "self": "https://jmwe-dev-local.atlassian.net/rest/api/2/customFieldOption/10100",
    "value": "Radio1",
    "id": "10100"
  },
  {
    "self": "https://jmwe-dev-local.atlassian.net/rest/api/2/customFieldOption/10101",
    "value": "Radio2",
    "id": "10101"
  }
]

 See https://developer.atlassian.com/cloud/jira/platform/jira-expressions-type-reference/#issue for details (under "custom fields")

Like Darryl Lee likes this

Thanks, this is really helpful! Heh, the documentation, not so much:

In addition to these, all custom fields are available and can be referenced by one of the following:

  • ID: issue.customfield_10010
  • key: issue['com.my.app.field-key']

Custom fields are returned as JSON values, using exactly the same format as in the issue REST API.

I mean I guess if I was intimately familiar with the REST API I would know they were returned as objects.

Anyways, I really do appreciate your taking the time to explain!

0 votes

I assume you want validation to succeed if the user selects only "None", and fail if he doesn't select anything?

Then try this:

!!issue.customfield_12308 && (issue.customfield_12308.some(it => it.value == "None") && issue.customfield_12308.length == 1 || !issue.customfield_12308.some(it => it.value == "None"))

Which means:

  • customfield_12308 must not be empty, AND:
    • customfield_12308 contains None and no other value, OR
    • customfield_12308 does not contain None

Hello @David Fischer _Innovalog_ @Radhika Vijji _Innovalog_ 

Wondering if  you can please help me?

I'm trying to build a validation that will block a transition for a specific Issue type when it meets certain conditions. 

IF

  • Issue Type Name = "New Award"
  • Sponsor Code(single text field) has one of the following values (5101,5105,5106, etc...)

Then 

Block Transition when

  • Multi Valued Check Box field "Check all that apply" does not have the value "X" checked. In other words, the person needs to at least select the value "X", otherwise, the transition is blocked.

What I've done so far is tried to use the Field Required Validator with the following condition:

(issue.issueType.name=="New Award"
&& (!issue.customfield_10117 || !issue.customfield_10117.some(it => it.value == "X"))
&& (issue.customfield_10075 == "5101"
||issue.customfield_10075=="5105"
||issue.customfield_10075=="5106"
||issue.customfield_10075=="5107"
||issue.customfield_10075=="5109"
||issue.customfield_10075=="5112"
||issue.customfield_10075=="5118"
||issue.customfield_10075=="5124"
||issue.customfield_10075=="5128"
||issue.customfield_10075=="5130"
||issue.customfield_10075=="5132"
||issue.customfield_10075=="5133"
||issue.customfield_10075=="5136"))

But, this has not worked. Any Help would be much appreciated. 

Thank You!

Ernesto

Hi @Ernesto Donate ,

the logic in your script is slightly incorrect. You want the script to return true when the transition should be allowed, so the first test should be to return true if the issue type is not New Award.

Try this instead:

issue.issueType.name != "New Award" || !["5101","5105","5106","5107","5109","5112","5118","5124","5128","5130","5132","5133","5136"].includes(issue.customfield_10075) || !!issue.customfield_10117 && issue.customfield_10117.some(it => it.value == "X")

This means that the validation will pass if:

  • issue type is not New Award
  • or if it is, then if customfield_10075 is not in the list of values
  • or if it is, if X is selected

Hello @David Fischer _Innovalog_ , 

This is been very helpful! I have a few related questions

  • If I want to include more than one Award Type would it be correct to use something like: !["New Award","IssueNameX","IssueNameY"].includes(issue.issueType.name)
  • In general for validators that involve multiple conditions it is correct to use the "build-your-own" option instead of the "Field required Validator" with a condition?

Thanks again!

Ernesto

Hi @Ernesto Donate ,

  1. Correct
  2. It really depends. If you're really trying to make a single field mandatory, but only under certain circumstances, it's usually easier to use the Field required (JMWE app) Validator. But in your case, that's not what you're doing, since you want to test the value of customfield_10117, not just whether it is empty or not. In that case, you have no choice but to use a Build-your-own validator.

Suggest an answer

Log in or Sign up to answer
TAGS

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