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,298,057
Community Members
 
Community Events
165
Community Groups

ScriptRunner Behaviour problem checking current form value

Edited

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

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 

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
DEPLOYMENT TYPE
SERVER
VERSION
8.22.2
TAGS
Community showcase
Published in Jira Software

Upcoming changes to epic fields in company-managed projects

👋 Hi there Jira Community! A few months ago we shared with you plans around renaming epics in your company-managed projects. As part of these changes, we highlighted upcoming changes to epics on...

14,809 views 37 48
Read article

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