Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,369,450
Community Members
 
Community Events
168
Community Groups

How to set the acceptance limit for a "issue field custom field"

I have created a Issue field "TTL", where it will accept only numeric value in seconds. I need to set the limit to be accepted any where between (>= 60 seconds and <=8400 seconds). PFA. Any one kindly assist how to set the limit ?

TTL.JPG

 

 

3 answers

1 accepted

Hi @Hemanth Kumar

Why do you want to convert the form field value to a String and use Regular Expressions?

Since you have the requirement to check if the value entered into the field is from the range of 60 to 8400, why not just convert it to a numeric type, i.e. Integer or Long?

It would help if you tried something like:-

def field = getFieldById(fieldChanged)
def fieldValue = field.value as Integer

field.clearError()

if(fieldValue && (fieldValue < 60 || fieldValue > 8400)) {
field.setError('The Value Entered is out of Range')
}

Please note that the sample code provided is not 100% exact to your environment. Hence, you will need to make the required modifications.

I hope the sample code above helps to solve your question. :)

Thank you and Kind regards,

Ram

@Ram Kumar Aravindakshan _Adaptavist_  you are right, i have later updated as integer value. thanks for the above script, it helped.

Minor update, there was missing close bracket ')' , i have updated and used.

Hi @Hemanth Kumar

Glad to hear the solution worked for you. :)

Thanks for letting me know about the code error; I have updated the sample code.

Thank you and Kind regards,

Ram

Like Hemanth Kumar likes this
0 votes

Hi @Hemanth Kumar ,

you can't do that using builitin features. You need to use a third part plugin such as ScriptRunner to put in place a rule through a behaviour.

Fabio

Thanks! @Fabio Racobaldo _Herzum_  will see to create a script runner then

@Fabio Racobaldo _Herzum_  I was able to create script with some help of google/community and figured out to ranging from 60 to 100, but can you assist how to fix the range to 3 digit and 4 digit value. (as mentioned in above - 60 - 8400 is my requirement)

 

import com.onresolve.jira.groovy.user.FormField

FormField formField = getFieldById(getFieldChanged())
String value = formField.getFormValue() as String
if (value) {
    if (!value.matches("[6-9][0-9]|100")) {
        formField.setError("value should be bet. 60-8400")
    } else {
        formField.clearError()
    }
} else {
    formField.clearError()
}

@Ram Kumar Aravindakshan _Adaptavist_ 

I was able to create script with some help of google/community and figured out to ranging from 60 to 100, but can you please assist how to fix the range to 3 digit and 4 digit value. (as mentioned in above - 60 - 8400 is my requirement)

 

import com.onresolve.jira.groovy.user.FormField

FormField formField = getFieldById(getFieldChanged())
String value = formField.getFormValue() as String
if (value) {
    if (!value.matches("[6-9][0-9]|100")) {
        formField.setError("value should be bet. 60-8400")
    } else {
        formField.clearError()
    }
} else {
    formField.clearError()
}

Suggest an answer

Log in or Sign up to answer