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
The Atlassian Community can help you and your team get more value out of Atlassian products and practices.
Hey all,
I'm sure this is pretty easy but I'm pretty clueless with scripting. Could someone help me with a behavior that would only allow 2 characters and values of 0-25? Custom Field ID is 11850.
Hi @Scott Federman ,
which type does your custom field have? Is it a Number Field or Text Field (single line)? Thank you.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
the field's type is ok :-).
import com.onresolve.jira.groovy.user.FormField
FormField formField = getFieldById(getFieldChanged())
String value = formField.getValue() as String
if (!value.matches("[0-9]|1[0-9]|2[0-5]")) {
formField.setError("Your error message")
} else {
formField.clearError()
}
Please add it as a server-side script to your customfield and try :-).
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.
@Hana Kučerová i did notice one other problem. It works great on the edit screen, but there is no restriction from the view screen which is allowing me to put any number in the fields via inline editing.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Scott Federman Please check the mapping (issue types, projects) and configuration of your Behaviour. Field's inline edit should not be not possible, when there's a validator, and Jira should automatically open the full edit screen, when you click on the pencil icon.
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.
did you try to move to another field, after you've entered the correct value (like 14)?
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.
Thanks!
Please try to test this code:
import com.onresolve.jira.groovy.user.FormField
FormField formField = getFieldById(getFieldChanged())
String value = formField.getValue() as String
if (value) {
if (value != "test") {
formField.setError("error")
} else {
formField.clearError()
}
} else {
formField.clearError()
}
Then it should work like this:
Each time you change the value of the field, move to the next field. Then the validator should be called (you can check in browser's console - there should be activity on the Network tab)
Maybe there is something wrong with the regex, but it works for me :-(...
Which version of Jira and ScriptRunner do you have?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Hana Kučerová here are my results
We are using Jira 8.4.1 and scriptrunner 5.6.6.1-jira8
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Scott Federman It seems to me, that your custom field must have Number Field type (not Text Field (single line)). Is it possible?
Are there any other behaviours defined for your project?
Thanks.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Hana Kučerová You know i could have sworn they were text fields but you are correct. They are number fields.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Scott Federman Thing happens :-)...
If it is a number, what about the values like 14.0 ? Are they valid or not? And what about 14.5? Thanks...
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.
@Scott Federman Last try :-)
import com.onresolve.jira.groovy.user.FormField
FormField formField = getFieldById(getFieldChanged())
String value = formField.getFormValue() as String
if (value) {
if (!value.matches("[0-9]|1[0-9]|2[0-5]")) {
formField.setError("Your error message")
} else {
formField.clearError()
}
} else {
formField.clearError()
}
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.
Hello @Hana Kučerová
I am also rookie in scripting. I spent hours of time to change if condition for custom field but didn´t find working solution. My condition should be:
Value of the custom field must contain exact 7 digits (not less, not more, only digits not letters).
Could you help me with this condition please? Thank you very much.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Hana Kučerová first of all, thanks for the attempts and patience. Can you please help me understanding below line ?
if (!value.matches("[0-9]|1[0-9]|2[0-5]")) {
I need to set the limit of an field to accept value only if its between (60 - 8400), this is numeric field these are values in seconds
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Hana Kučerová 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)
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.
@Hana Kučerová It worked thanks a lot. But i would like to understand the format styling please.
I tried (("[6-9][0-9]|100") && ("[0-9][0-9][0-9]|1000")) assuming - 60 to 100 and 101 to 1000, but it didn't worked.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
6[0-9] .. 60 - 69
[7-9][0-9] .. 70 - 99
[1-9][0-9]{2} .. 100 - 999
[1-7][0-9]{3} .. 1000 - 7999
8[0-3][0-9]{2} .. 8000 - 8399
8400 .. 8400
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.
Hi @Hana Kučerová ,
Thanks for your script. it worked for me too.
Along with this script, i have extended requirement ie; my text field should not exceed more than 10 characters and it should allow only 0-9 numbers.
Help required from you:
import com.onresolve.jira.groovy.user.FormField
FormField formField = getFieldById(getFieldChanged())
String value = formField.getValue() as String
if (!value.matches("[0-9]{1,256}")) {
formField.setError("Your error message")
} else {
formField.clearError()
}
can you tell us how can we add "|" as multiple value separator.
[0-9]{1,256} is to keep field max length is 256 characters. we need to modify script as to add "|" as multiple value separator.
Expected:
Field_name= 1234|456|7890|..
can you help?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Scott Federman - glad you were able to resolve the validation problem. If this is something you need to build often, you could try ProForma (or ProForma Lite - a free version of the app) for a simpler way to build validation. Full disclosure, I'm on the ProForma team.
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.