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

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 vote
Alexey Matveev Community Champion Nov 02, 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
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Bridget Sauer
Published Thursday in Marketplace Apps

Calling all developers––You're invited to Atlas Camp 2018

 Atlas Camp   is our developer event which will take place in Barcelona, Spain  from the 6th -7th of   September . This is a great opportunity to meet other developers and get n...

365 views 0 6
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you