Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

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

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

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

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
FREE
PERMISSIONS LEVEL
Product Admin
TAGS
AUG Leaders

Atlassian Community Events