Proper way to use JMWE Validators with select list custom field

Daniel Burris June 14, 2021

Hello. I'm trying to do the following using JIRA Misc workflow extensions (JMWE) validators as a bit of an approval process. Basically if a field (10059, multi select list) is NOT set to None (which is the default no value for this field by JIRA). Then it needs to have one of the few people in the select list (10057) to pass validation.  Here is the basic expression that I thought  would work:

 

!!issue.customfield_10059 && issue.customfield_10059.some(it => it.value != "None") &&
!!issue.customfield_10057 && issue.customfield_10057.value == "a value in the list"

 

I tried the inverse of some of the logic above, but I cant see to get it work. It seems to always through the validation error, or never throw it. I'm pretty sure I' missing something simple, but I'm new to these type of expressions. 

 

As a bonus, it'd be nice to allow for a few values out of the list in 10057 allow it to pass validation (it'd be 3 names out 10 in that list. Something like  10057.value.containts("Approver 1", "Approver 2", "approver 3"). 

4 answers

2 votes
Atlassian Learner January 31, 2023

Hi @David Fischer , Many thanks as always, it worked perfectly, Kudos to you.

Regards,

Ajay

1 vote
David Fischer
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 30, 2023

Hi @Atlassian Learner 

it's similar to what I shared earlier:

!!issue.customfield_10000 || 
!!issue.customfield_10010 && !["N/A","No"].includes(issue.customfield_10010.value)
&& !!issue.customfield_10011 && !["N/A","No"].includes(issue.customfield_10011.value)
&& !!issue.customfield_10012 && !["N/A","No"].includes(issue.customfield_10012.value)
&& !!issue.customfield_10013 && !["N/A","No"].includes(issue.customfield_10013.value)

where  customfield_10000 is the ID of the Reason field, and customfield_10010...customfield_10013 are the IDs of the four dropdown fields.

1 vote
David Fischer
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
June 14, 2021

Hi @Daniel Burris 

First of all, is "None" an actual option you have configured on your multi-select field, or does it denote that no value is selected? I assume the latter.

In that case, the internal value of the field is... null. 

Then the problem is with your logic. The Build-your-own validator should pass if either customfield_10059 is empty or (if it isn't empty) customfield_10057 has a desired value. So the code should be:

!issue.customfield_10059 || !!issue.customfield_10057 && issue.customfield_10057.value == "a value in the list"

 And for multiple acceptable values:

!issue.customfield_10059 || !!issue.customfield_10057 && ["val1","val2","val3"].includes(issue.customfield_10057.value)
0 votes
Atlassian Learner January 30, 2023

Hi @David Fischer , Seems you are every were for the JMWE logics.

Can you please help me here, we have four dropdown fields with values Yes, No ,  N/A, other and have a text field with name Reason.

Here when ever the field Reason is null(Empty) then the values of the four fields ( Field 1, field 2, field 3 , field 4 ) values should not be equal to N/A or No.

Can you please provide Build-your-own (scripted) Validator expression in create screen.

Thanks in advance for the help

Regards,

Ajay

Atlassian Learner January 31, 2023

Hi @David Fischer ,  one more help please,

I want to set the A drop down field values to no based on another dropdown field values.

If the field A is set to yes then second field should select the No value. tried with below code but not able to achieve the required

issue.customfield_10007.value || !! issue.customfield_10007.value == "YES" && issue.customfield_10032.value == "NO"

 Thanks again,

Ajay

David Fischer
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
February 1, 2023

Hi @Atlassian Learner 

Can you please reformulate you're requirements, I didn't quite get what you need. 

Atlassian Learner February 1, 2023

@David Fischer , thanks for the prompt response,

Assume we have two dropdown fields A and B with same values Yes, No , N/A, 

If Field A is set to Yes on create then field B should not accept the values Yes , N/A it should only accept the value No.

Hope it make sense now.

Thanks,

Ajay

David Fischer
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
February 1, 2023

I think I understand the desired validation. The script would be:

!issue.customfield_10007 || issue.customfield_10007.value != "Yes" || issue.customfield_10032.value == "No"

(note that the values are case-sensitive) 

Suggest an answer

Log in or Sign up to answer