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.
Hi @Scott Federman
did you try to move to another field, after you've entered the correct value (like 14)?
@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.
Hi @Hana Kučerová its a text field...although i can change it to a number field if need be.
the field's type is ok :-).
import com.onresolve.jira.groovy.user.FormFieldFormField formField = getFieldById(getFieldChanged())String value = formField.getValue() as Stringif (!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 :-).
@Hana Kučerová Its close! Its not allowing me to put any number in there at all though.
@Hana Kučerová ive tried moving to the next field as well as editing and have had no luck
Thanks!
Please try to test this code:
import com.onresolve.jira.groovy.user.FormFieldFormField formField = getFieldById(getFieldChanged())String value = formField.getValue() as Stringif (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?
@Hana Kučerová here are my results
We are using Jira 8.4.1 and scriptrunner 5.6.6.1-jira8
@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.
Interesting. You are correct. I'm not sure what was going on earlier.
@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.
It looks like you're new here. Sign in or register to get started.