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 votes
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
Community showcase
Published Oct 31, 2018 in Marketplace Apps

Marketplace Spotlight: Zephyr

Hello Atlassian Community! Each month, we run a series of Spotlights to highlight Marketplace vendors and apps that our team thinks this Community would find valuable. In last month's Spotlig...

349 views 0 1
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