Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Celebration

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,456,333
Community Members
 
Community Events
176
Community Groups

Compare value in User Picker custom fields

Hi,

Appreciate some guidance from experts in the community on how to write a Behaviour script to compare 2 user picker custom fields to ensure they are not the same users.

For example, in User Picker A, User A is selected. In User Picker B, User A cannot be selected again and returns an error.

Thank you in advanced.

Kind regards,

Kelvin

2 answers

1 accepted

0 votes
Answer accepted

Hi Kelvin

That's a fairly basic use case.

def fieldA = getFieldByName('User Picker A')
def fieldB = getFieldByName('User Picker B')
def currentField = getFieldById(fieldChanged)

fieldA.clearError()
fieldB.clearError()

if(fieldA.value == fieldB.value){
currentField.setError("Please select a different user. $currentField.value was already used.")
}

Put this script in the server-side script for both fields.

It will set an error message in the most recently modified field and clear the error if either fields are corrected.
Adjust for your actual field names (of change to getFieldById('customfield_xxxxx'))

Hi Peter.

Thank you so much for the assist. I've tested the script and it is working perfectly.

Kind regards,

Kelvin

Hi Peter,

Just a follow up question, I noticed when both fields are empty the error would appear. Is there a way for the error not to appear when both fields are empty?

Thanks.

If you only want to validate when the fields are not empty, you can add some logic like this:

if(fieldA.value && fieldB.value){
if
(fieldA.value == fieldB.value){
currentField.setError("Please select a different user. $currentField.value was already used.")
}
}

or combine it:

if(fieldA.value && fieldB.value && fieldA.value == fieldB.value){
currentField.setError("Please select a different user. $currentField.value was already used.")
}

Good afternoon. I would be very grateful for help with the question of how to compare the user selection field with the multiple selection of users. and if there is a match, issue an error message. cannot be done on its own.
an example of an article where the fields are compared with the user's choice.

Here thus I try to compare on matches of a field of a multiple choice of users. but i lack skills

import com.atlassian.jira.component.ComponentAccessor

// Get a pointer to my custom fields
def SelectList1 = getFieldByName("customfieldname")
def SelectList2 = getFieldByName("customfieldname2")

def currentField = getFieldById( fieldChanged )

SelectList1.clearError()
SelectList2.clearError()

// Get the Value of My Select Field
def selectVal1 = SelectList1.getValue() as String
def selectVal2 = SelectList2.getValue() as String

// If the first option is selected in the multi select list then make the text field required.
SelectList1.getValue().each {
if(selectVal1.contains(selectVal1) == selectVal2.contains(selectVal2)) {
currentField.setError( "Пожалуйста, выберите другого пользователя. Значение $currentField. уже было использовано." )}
}

Suggest an answer

Log in or Sign up to answer
TAGS

Atlassian Community Events