Transition should be blocked on Duplication selection of Custom Fields value
Asked by Prathap DL:

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)


Answers:
author: David Fischer
body: Hi [@Prathap DL](/t5/user/viewprofilepage/user-id/5541334)

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.

comments: author: Prathap DL
body: Hi [@David Fischer](/t5/user/viewprofilepage/user-id/538255)

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


author: David Fischer
body: Hi [@Prathap DL](/t5/user/viewprofilepage/user-id/5541334)

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))
```


author: Prathap DL
body: Hi [@David Fischer](/t5/user/viewprofilepage/user-id/538255) Getting below Error.

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


author: David Fischer
body: 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))
```


author: Prathap DL
body: [@David Fischer](/t5/user/viewprofilepage/user-id/538255)It 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,


author: David Fischer
body: Unfortunately, I don't believe this is possible. It's a limitation of Jira Cloud.


author: Nagabharana S
body: Hello [@Prathap DL](/t5/user/viewprofilepage/user-id/5541334) ,

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."`

comments: author: Prathap DL
body: Hi [@Nagabharana S](/t5/user/viewprofilepage/user-id/5026207)

Thanks for the Reply.

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


Tags: cloud

jira-cloud