Forums

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

How to limit Number Field to a range of natural numbers (with Script Runner)

Michaela Gluchow November 2, 2017

Hi,

I am looking for a way to limit the range of a number field to a certain range of natural numbers. This should always apply and not only in a certain workflow step. I tried to add Javascript to the description as described here. But I guess I am lacking of some important details. 

I thought of using Behaviors provided by Script Runner but also lacking of the implementation details. Perhaps someone has some hints or even a detailed description of how to do it.

Cheers,

Michaela

1 answer

0 votes
Alexey Matveev
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.
November 2, 2017

Hello, 

You need to create a behavour. In the field part of the behavour add your customfield. Then push create serverside script button. I am not sure that I understand correctly your required condition but the script will be like the following:

def cs = getFieldByName("CustomFieldNAme")

if (cs.getValue().toString().length() < 2) {
  cs.setError("Hello error")
  cs.setRequired(true)
} else {
  cs.setError("")
  cs.setRequired(false)
}

You can read more about behavours here:

https://scriptrunner.adaptavist.com/4.3.1/jira/behaviours-overview.html#_description

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events