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

Hemanth Kumar September 21, 2022

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

0 votes
Answer accepted
Ram Kumar Aravindakshan _Adaptavist_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
September 26, 2022

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

Hemanth Kumar September 26, 2022

@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.

Ram Kumar Aravindakshan _Adaptavist_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
September 27, 2022

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
Fabio Racobaldo _Herzum_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
September 21, 2022

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

Hemanth Kumar September 21, 2022

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

Hemanth Kumar September 26, 2022

@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()
}
0 votes
Hemanth Kumar September 21, 2022
Hemanth Kumar September 26, 2022

@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