The Atlassian Community Forums are currently in read-only mode. We will be relaunching on a new platform on September 22 (read more here). We apologize for the extended downtime. For concerns or questions, please email communitymanagers@atlassian.com. See you on the other side, on the new Atlassian Community Forums! :)

×

Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 
  • Community
  • Q&A
  • Jira
  • Questions
  • Want to add Regex for a custom field using ScriptRunner behaviour and give the error when regex fail

Want to add Regex for a custom field using ScriptRunner behaviour and give the error when regex fail

Sourav tulsyan
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
January 23, 2025

 

 

// Get the field by name
const workloadField = getFieldById('customfield_10065')
const value = workloadField.getValue();
// Regular expression to match a number or a float
const match = /^[0-9]+(\.[0-9]+)?$/.test(value);

if (!match && value.toString().length > 0) {
     workloadField.setError("The value has to be float (ex: 1, 1.5)");
} else {
     workloadField.clearError();
}

1 answer

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

0 votes
Answer accepted
Kristian Walker _Adaptavist_
Community Champion
January 24, 2025

Hi Sourav,

I can confirm that inside Jira Cloud, Behaviours does not provide a set error message, which means you will not be able to achieve your requirement of displaying error text.

You can see what fields and methods Behaviours supports Cloud in the documentation page located here, and the closest method to setError() would be setDescription() method to set some description text below a field.

This means in your script if you change setError to setDescription and change clearError() to setDescription("") then your logic would set the value as a description below the field.

I hope this information helps.

Regards,

Kristian

DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
FREE
PERMISSIONS LEVEL
Product Admin
TAGS
AUG Leaders

Atlassian Community Events