Just a heads up: On March 24, 2025, starting at 4:30pm CDT / 21:30 UTC, the site will be undergoing scheduled maintenance for a few hours. During this time, the site might be unavailable for a short while. Thanks for your patience.

×

Forums

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

Transition should be blocked on Duplication selection of Custom Fields value

Prathap DL
Contributor
August 22, 2024

Hello Community

I have 3 custom fields which are Multi select drop down. All 3 custom fields displays Same values. When User select Same value in more than 1 custom field and do the transition then its should not allow user to do the transition. Is there any way that i can use Jira validators to validate the duplicates and display the Error message.

 

Ex: Custom Field 1: Apple, Orange

     Custom Field 2: Mango, Orange

     Custom Field 3: Banana, Strawberry

In above example user selected Orange in 2 custom Fields. So when user do the transition It should check field values in all 3 custom fields and if they found duplicates then it should display error message and blocks the Transition.

 

Note: We are using Jira Cloud with Jira Misc Workflow Extensions (JMWE)

2 answers

1 accepted

1 vote
Answer accepted
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.
August 22, 2024

Hi @Prathap DL 

since you're on Jira Cloud, you can use a "Build-your-own Validator (JMWE app)" validator on the transition, with code written using Atlassian's Jira Expressions language:

let field1 = issue.customfield_12345.map(val => val.value);
let field2 = issue.customfield_23456.map(val => val.value);
let field3 = issue.customfield_34567.map(val => val.value);
!field1.some(val => field2.includes(val) || field3.includes(val)) && !field2.some(val => field3.includes(val))

where you'll replace customfield_12345 with the custom field ID of your first Multi select drop down custom field, customfield_23456 with the custom field ID of your second Multi select drop down custom field, and customfield_34567 with the custom field ID of your third Multi select drop down custom field.

Prathap DL
Contributor
August 22, 2024

Hi @David Fischer 

Thanks for the Answer.

The Jira expression working when There is a duplicate. But I'm also facing one issue that, whenever all 3 fields are empty or 1 of the field is empty That time also script is blocking the transition.

I need to run this script when "Conditional validation" to check  Jira expression value.

With above Jira expression there are 3 results will display.

1. True: When all 3fields are filled and there are no duplicates

2. False: When all 3 fields are filled and there are duplicates

3. Error: When any one of the Field is empty or all the 3 Fields are empty.

 

Now I want this expression to block the transition when Jira value is "False".

 For True or Error it should ignore and allow the Transition.

Also is there any way that we can get Proper message instead of Generic message.

For Ex: Custom Field 1: Apple, Orange

     Custom Field 2: Mango, Orange

     Custom Field 3: Banana, Strawberry

"Orange" is selected in more than 1 custom field

 

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.
August 23, 2024

Hi @Prathap DL 

sorry, i forgot to include code in my script for that. Try this:

let field1 = issue.customfield_12345?.map(val => val.value) || [];
let field2 = issue.customfield_23456?.map(val => val.value) || [];
let field3 = issue.customfield_34567.map(val => val.value) || [];
!field1.some(val => field2.includes(val) || field3.includes(val)) && !field2.some(val => field3.includes(val))
Prathap DL
Contributor
August 23, 2024

Hi @David Fischer  Getting below Error.

Evaluation failed: "issue.customfield_14277?.map(val => val.value)" - issue.customfield_14277?.map (null) is not a function

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.
August 23, 2024

Can you try this:

let field1 = issue.customfield_12345 ? issue.customfield_12345.map(val => val.value) : [];
let field2 = issue.customfield_23456 ? issue.customfield_23456.map(val => val.value) : [];
let field3 = issue.customfield_34567 ? issue.customfield_34567.map(val => val.value) : [];
!field1.some(val => field2.includes(val) || field3.includes(val)) && !field2.some(val => field3.includes(val))
Prathap DL
Contributor
August 23, 2024

@David FischerIt worked

"I really appreciate your assistance, it made all the difference in solving my problem!".

One last question, Currently i added Generic message in Error Message Field that says "duplicate value is selected in more than 1 custom Field".

Instead of this Can we add the duplicate field value with Error message.

Ex: Orange is selected in more than 1 custom Field

Thanks, 

 

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.
August 23, 2024

Unfortunately, I don't believe this is possible. It's a limitation of Jira Cloud.

Like Prathap DL likes this
0 votes
Nagabharana S
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
August 22, 2024

Hello @Prathap DL ,

Use the below script in the Groovy and try. Add a "Scripted (Groovy) Validator" from JMWE.

def field1 = issue.get("customfield_1")?.toSet() ?: []
def field2 = issue.get("customfield_2")?.toSet() ?: []
def field3 = issue.get("customfield_3")?.toSet() ?: []

def allValues = field1 + field2 + field3
def duplicates = allValues.findAll { value -> allValues.count(value) > 1 }.unique()

if (duplicates) {
return false // This will block the transition
}

return true

When you set up the validator, you can specify an error message that will be displayed to the user if duplicates are found. For example: "You have selected the same value in more than one field. Please ensure each value is unique across the custom fields."

Prathap DL
Contributor
August 22, 2024

Hi @Nagabharana S 

Thanks for the Reply.

Where exactly I need to put this code. I don't see Scripted (Groovy) Validator" from JMWE.

Suggest an answer

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

Atlassian Community Events