This request initially began as an attempt to limit the number of users that could be selected in a multi-user picker field.
One of the service requests in JSD allowed customers to request a new shared mailbox along with the people who should have access. There is a limit of 18 people who can have access.
Looking into behaviors, I found that the function formField.getValue() does not return a list of users, but rather returns a String. How can I retrieve each user object to perform validations?
FYI - I am no longer trying to limit the number of users, we are instead warning people in the help text not to select more than 18. This question relates more to the general idea of checking the contents of a multi user picker field for whatever validations we want.
Initial code used to "Solve" the above 18 limit. Note that we are counting the number of commas as I couldn't cast the list to application users.
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.user.util.UserUtil
import com.atlassian.jira.user.ApplicationUsers
//Get the Owner custom field
def owners = getFieldByName("Add Users")
def ownerValue = owners.getValue() as List<String>
def count = 0
def fieldValues =
//Count the number of commas present. This will give us a number of values 1 larger than the number of commas we find.
ownerValue.each{
if(it == ","){
count++
}
}
//If there is more than 17 commas, we have more than 18 values. Set an error on the field.
if(count >17){
owners.setError("Only 18 users may have access too this mailbox, please reduce the number of users selected.")
}
else{
owners.clearError()
}