Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 
  • Community
  • Q&A
  • Jira
  • Questions
  • We want to restrict the numeric custom fields in JIRA to accept only positive numbers or zero.

We want to restrict the numeric custom fields in JIRA to accept only positive numbers or zero.

Likhita January 29, 2024

Hi,

I'm looking for a Solution to restrict a numeric custom field for accepting only positive integers or value Zero

In few occasions, members are entering an invalid numbers, such as:

-negative numbers

Need restriction on the numeric field in global level projects.

Can anyone suggest on this please?

Thanks,

2 answers

1 accepted

2 votes
Answer accepted
Aswin Raj D
Community Champion
January 29, 2024

Hi @Likhita ,

Then you can try with script runner behavior script. 

  • Map the Behavior to Projects and Issue Types: In the 'Fields' section, map the behavior to specific projects and issue types where you want this restriction to apply.

  • Add the Field: Click on 'Add Field.' Select the numeric custom field you want to apply the validation to.

  • Write the Script:

import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript

@BaseScript FieldBehaviours fieldBehaviours

def numericField = getFieldById(fieldChanged) // Replace with your field's ID
def numericValue = numericField.getValue() as Double

if (numericValue != null && numericValue < 0) {
numericField.setError("Please enter a positive number or zero.")
} else {
numericField.clearError()
}

Likhita January 30, 2024

It worked thank you

Like Aswin Raj D likes this
0 votes
Likhita January 29, 2024

Hi ,

Thank you for your quick response and help.

Using Validator we can restrict only at specific transition level if i want to add it for all the projects then I need to add in all the workflows its time taking process.

Thanks

 

 

Cyrille Martin
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 31, 2024

Suggest an answer

Log in or Sign up to answer