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,295,560
Community Members
 
Community Events
165
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

1 answer

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.")
}

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Posted in Jira Service Management

Jira Service Management Documentation Opportunities

Hello everyone, Hope everyone is safe! A few months ago we posted an article sharing all the new articles and documentation that we, the AMER Jira Service Management team created. As mentioned ...

301 views 0 9
Join discussion

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you