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.
Interesting. You are correct. I'm not sure what was going on earlier.
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.
@[deleted] 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.
@Hana Kučerová My requirement is in the Numeric field type (Data Center) value has to be between 00000 and 99999. Using https://3widgets.com/, I got the expression as
(0{4}[0-9]|0{3}[1-9][0-9]|00[1-9][0-9]{2}|0[1-9][0-9]{3}|[1-9][0-9]{4})
Wrote the below Behavior on the field as below and it does not work (accepts decimals, more than 5 characters etc)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Venkat_Suresh Maybe
[0-9]{5}
? But you probably need to change it to the text field because of the leading zeros.
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á Even after changing to Text field type, below behavior does not error when entered characters.
Character field validations
import com.onresolve.jira.groovy.user.FormField
FormField formField = getFieldById(getFieldChanged())
String value = formField.getFormValue() as String
if (value) {
if (!value.matches("(0{4}[0-9]|0{3}[1-9][0-9]|00[1-9][0-9]{2}|0[1-9][0-9]{3}|[1-9][0-9]{4}|[0-9]{5})") {
formField.setError("value should be bet. 00000-99999")
} else {
formField.clearError()
}
} else {
formField.clearError()
}
Any other ideas? or pointers?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Venkat_Suresh Have you tried
[0-9]{5}
instead of
(0{4}[0-9]|0{3}[1-9][0-9]|00[1-9][0-9]{2}|0[1-9][0-9]{3}|[1-9][0-9]{4}|[0-9]{5})
?
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á Thank you for the response so far.
Tried as below on a Character field
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Finally figured the solution on a text field
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.
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.