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
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.")
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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. уже было использовано." )}
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.