You're on your way to the next level! Join the Kudos program to earn points and save your progress.
Level 1: Seed
25 / 150 points
Next: Root
1 badge earned
Challenges come and go, but your rewards stay with you. Do more to earn more!
What goes around comes around! Share the love by gifting kudos to your peers.
Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!
Join now to unlock these features and more
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.