Need scriptrunner code for single line text field with restricting 0-9 numbers with 10characters length from create, edit screen.
I am able to keep restrict in create screen with validator in workflow for create transition.
regex used in validator is: ^[0-9]{1,10}$
But its allowing to update field from view/edit screen.
Can i get help here?
Hi @Kishore D
Are you using Behaviors?
If so,
Add the mappings to the related project and issue type.
Select the field for which you need this validation for. And click on 'Add server-side script'.
Add the below code:
def field = getFieldByName("Name of the custom field")
//Or
//def field = getFieldById("customfield_xxxxx")
if ((field?.value as String)?.length() > 10) {
field.setError("Length of the field should not be more than 10 characters")
}
else {
field.setError("")
}
Hi @Vamsi Kandala ,
Thanks for sharing code. I managed with below code
import com.onresolve.jira.groovy.user.FormField
FormField formField = getFieldById(getFieldChanged())
String value = formField.getValue() as String
if (!value.matches("[0-9]{1,10}")) {
formField.setError("Your error message")
} else {
formField.clearError()
}
But, here i want to add some other part like,
I will put total length of filed as 256. And the field should allow multiple values with "|" as value separator.
so my field should allow like custom_filed112=1234|56|789|23456
if possible, can you help with this behavior?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Kishore D
Can you try using '[0-9|]{1,10}'?
Note the pipe character '|' after the digit '9'.
Thanks,
Vamsi
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks @Kishore D
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.