Forums

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

Check selection in Multi select custom field for specific Value Scriptrunner Cloud

Ismael Jimoh
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.
October 25, 2022

Hi All,

I have a validator on Issue creation that checks that no other value is selected if a specific value from a multiselect is selected.

The problem however is I am unsure how to check in a validator what value was selected.

I have tried both:

issue.customfield_10085.includes("a") 

and 

issue.customfield_10085.value =="a"

 

The former I would assume is the expected method but it doesn't work and always returns a false even if "a" is an option that has been selected in the multi-select field. The later fails because value is not a known property.

I get the following error for the second:

Evaluation failed: "issue.customfield_10085.value" - Unrecognized property of `issue.customfield_10085`: "value" ('value'). Available properties of type 'List' are: 'concat', 'every', 'filter', 'flatMap', 'flatten', 'includes', 'indexOf', 'join', 'length', 'map', 'reduce', 'slice', 'some', 'sort'

So I will greatly appreciate if anyone could point me in the right direction of how to validate such a condition.

Also, I am open to alternative solutions for this if you are aware of any.

I saw https://community.atlassian.com/t5/Jira-Software-questions/Transition-Validator-for-custom-multi-select-field-that-must/qaq-p/1424625 and would likely try it out next as a workaround though I am not sure how to compare length in this case.

3 answers

1 accepted

3 votes
Answer accepted
Sayed Bares _ServiceRocket_
Community Champion
October 25, 2022

Hi Ismael,

You can use something like this:

!!issue.customfield_10085 && issue.customfield_10085.every(it=>it.value=="a")

The first part of the code will ensure that the customfield is not  empty and then the second part will assure that its value is only a

Best,

Sayed

Ismael Jimoh
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.
October 26, 2022

Thanks a lot Sayed.

I tried the following but I still get a false result.

Do you have any idea?

Thanks.

Sayed Bares _ServiceRocket_
Community Champion
October 26, 2022

@Ismael Jimoh 

False means the validator didn't pass, so it means your customfield didn't have the "a" as a value.

Best,

Sayed

Ismael Jimoh
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.
October 26, 2022

Hi Sayed,

The value was correctly selected.  

I will try this again and share a screenshot for you.

Thanks again.

Ismael Jimoh
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.
October 26, 2022

Please see the configuration and replies below:

Screenshot 2022-10-26 at 14.35.55.png

Issue View

Screenshot 2022-10-26 at 14.36.53.png

Confirming the customfield id from Browser console

Screenshot 2022-10-26 at 14.37.48.png

The query we agreed to work with.

The field is a multi-select custom field as you saw above and Adam is an option from the field. However as you saw, I still get an error false though the value is present.

I will appreciate it if you have any further suggestions.

Thanks.

Sayed Bares _ServiceRocket_
Community Champion
October 26, 2022

@Ismael Jimoh thanks for the screenshot.

The reason for that is that you have other values besides Adam, which is Erin.

If you want to pass the validator as long as you have Adam as a value, then use this code instead:

!!issue.customfield_10085 && issue.customfield_10085.some(it=>it.value=="Adam") 
Ismael Jimoh
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.
October 26, 2022

Thanks a lot @Sayed Bares _ServiceRocket_ .

This solved the issue for me.

Thanks a lot.

Like # people like this
1 vote
Max Foerster - K15t
Community Champion
October 25, 2022

Hey @Ismael Jimoh

Can you check whether this community question already helps in solving this?

I'm quoting @Alexey Paveliev

"Non-numeric custom fields are not available and need to be got via REST calls"

Best, Max

0 votes
Ismael Jimoh
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.
October 25, 2022

The above suggestion doesn't work as I am checking within a validator and this expects one to use JIRA Expressions.

If anyone is familiar with the expected expression, I would greatly appreciate this.

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
FREE
PERMISSIONS LEVEL
Product Admin
TAGS
AUG Leaders

Atlassian Community Events