Hello,
I am wondering if there was a way to validate information on an Edit Screen before Saving changes.
I have tree User Picker Fields. I want to validate that the same user does not exist more than once. The problem i I have is how to get the values from three different fields on the from the Edit UI.
I have seen references to the method getFieldChanged()
https://docs.adaptavist.com/sr4js/6.26.0/features/behaviours/api-quick-reference
Used as follows:
getFieldById(getFieldChanged())
But this is only mapped to the Field in a behaviour. It is not possible to use this to get the value of three different fields and then compare.
Another way I have seen is which appeared to promise is getFormValue()
I tried to use as follows:
def developerField = getFieldById("customfield_0000000")
def developerUser = developerField.getFormValue() as String
The tricky part here to place server-side script on each User Picker field in Beahviours.
For example, i have 3 user picker fields:
with IDs customfield_12300, customfield_12301 and customfield_12302.
Then i create behaviour and paste the same code on each:
This method capturing changes in each field and procced comparing and alerting
Hope it will help you! Let me know if you occure some problems or accept answer if not.
Thank you Sergy.
I think this is about half right. Though there is one problem with this solution. If I am to change users against the roles.
For example.
in the below image I have the users Red User, Orange User and Green User. If I update Change Owner from the Orange User to the Red User then I get the exception because when I make the change the Developer has the same value.
When I next update the Developer from the Red User to the Orange the Error message persists.
I am not sure if, with scriptrunner, this is actually possible. I was hoping that there was a method which would actually just validate the users when attempting to update an issue.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thank you for your response!
I shared a small trick earlier, but not a complete script that meets your needs. If you would like, I've written some code that might help. Please feel free to try pasting it into each server-side script of the User Picker Fields in Behaviors. I hope this is helpful!
def userPicker1 = getFieldById("customfield_12300")?.getValue() // Change owner
def userPicker2 = getFieldById("customfield_12301")?.getValue() // Developer
def userPicker3 = getFieldById("customfield_12302")?.getValue() // Tester
def errorMessage = "Error Duplicate Users."
def userPickers = [
[value: userPicker1, fieldId: "customfield_12300"],
[value: userPicker2, fieldId: "customfield_12301"],
[value: userPicker3, fieldId: "customfield_12302"]
]
def groupedByValue = userPickers.groupBy { it.value }
groupedByValue.each { value, entries ->
if (value != null && entries.size() > 1) {
entries.each { entry ->
getFieldById(entry.fieldId)?.setError(errorMessage)
}
} else {
entries.each { entry ->
getFieldById(entry.fieldId)?.clearError()
}
}
}
Don't forget to replace the field IDs with your own!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.