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
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)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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"?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi David - it's a multi-valued Checkbox field. "None" is an actual option.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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 must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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:
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")
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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")
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello @David Fischer @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
Then
Block Transition when
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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:
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello @David Fischer ,
This is been very helpful! I have a few related questions
Thanks again!
Ernesto
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Ernesto Donate ,
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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:
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.