ScriptRunner Behaviour problem checking current form value

Paul Stahlke May 17, 2022

Hi, I am trying to create a simple behaviour that gives an error when the user edits an issue and doesn't update the "Location" multi-select field away from "(Not yet set)" value. The problem with my code here is that when the user changes the value in the form to a valid option, it still gives me the error. It's not picking up the changed form value. Do you know how to fix this? Thanks.

def requiredField = getFieldByName("Location")

if ("(Not yet set)" in requiredField.value) {
requiredField.setError("Location is not yet set.")
}

1 answer

1 accepted

1 vote
Answer accepted
Ram Kumar Aravindakshan _Adaptavist_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
May 17, 2022

Hi @Paul Stahlke,

You are still getting the error message even though the value is set because you haven't set a clearError() option for the field. 

You should try something like:-

def requiredField = getFieldByName("Location")

requiredField.clearError()

if ("(Not yet set)" in requiredField.value) {
requiredField.setError("Location is not yet set.")
}

Also, if you have configured this for the Location field, i.e. as a Server-Side Behaviour, the better option would be to set the code as:-

def requiredField = getFieldById(fieldChanged)

requiredField.clearError()

if ("(Not yet set)" in requiredField.value) {
requiredField.setError("Location is not yet set.")
}

I hope this helps to answer your question. :)

Thank you and Kind regards,

Ram 

Paul Stahlke May 18, 2022

This is fantastic, Ram! Thanks very much. Adding the clearError() line fixed it perfectly. The second option with getFieldById(fieldChanged) works nicely as well. How does that method make it better?

Suggest an answer

Log in or Sign up to answer