I have several custom fields of type "Text Field (<255 characters)" and am wondering if there is a way to perform some workflow validations on the fields. For example, I have a "Zip Code" field that I know should always be 5 digits long. Any zip codes entered that are not 5 digits should be caught as invalid. Is there a way to build in these types of checks into the workflow as validators, or is there a way to further customize a text field by saying how many characters it should be ? I've searched Atlassian answers and the Plugin Exchange but haven't been able to find anything. Any help is appreciated!
Thanks!
It's a very specific request so I doubt there is anything built-in. It's easy to do though with minimal programming... eg install script runner, go to validators, add validator, -> script validators -> simple scripted validator.
Then the condition in your case would be:
cfValues["ZipCode"]?.length() == 5
Obviously, double-check the name of your custom field.
Also don't forget to mark my answer as correct if it works for you ;-)
And you can mark my comments as helpful if you like.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks! This works perfectly. Is it possible to use an OR statement? For example, my Zip field can be a 5 character string or N/A
cfValues['Current Zip'].length() == 5 OR cfValues['Current Zip'] == 'N/A'
This is what I tried but it is not working correctly. Thanks!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks ;-) It all helps in my quest to get to 2nd place...
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Just replace OR with ||
There is a condition tester builtin admin script, which is useful for honing your conditions/validators.
You can also do pattern matching, and more complex stuff than checking the length.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks! Will the custom field validator work on Cascading select fields?
For example, in my cascade select field called "Request type", the user first selects "Retail" then selects "Add". This shows up as a concatenation in the "Request type" field as "Retail - Add". Will this be recongnized by the custom field validator?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
+1 Jamie. Didn't know until know that custom field values are available as a map property :-)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Not in that way... for that example it would be like
def vals = cfValues["Request type"]?.allValues
vals[0] == "Retail" && vals[1] == "Add"
You can put as many lines in the condition as you want, it will expand as necessary.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Sorry for the multiple dumb questions, but I'm not an experienced groovy script user. Do I need to type more than the couple of lines mentioned above in my condition? It isn't working correctly and I am a bit lost since the link you are mentioning has a lot more too it than what I'm trying to do (I think).
def vals = cfValues["Request type"]?.allValues
vals[0] == "Retail" && vals[1] == "Add"
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Dieter - yeah, they're all chucked into the map for convenience. Only for conditions though IIRC. (and only in this plugin of course).
@Molly - > has a lot more too it than what I'm trying to do (I think)
what is it you're trying to do? I thought you wanted to validate a cascading select, but I'm sure there's more to it than that, as there's no point in validating that a field is only one value (in isolation).
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I am trying to validate a cascading select field at a workflow step. I only want the workflow step to be available if the cascading select field meets a certain criteria. I can write simple conditionals using the built in scripts, I just don't know how to use Groovy and don't know where to start.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
OK, so you need the Simple Script Condition (not validator). The condition for checking a cascading select should be what I put above... see what happens in the condition tester. Try that script both with an issue with the correct value, and issue with the wrong value, and an issue with no value. It might be necessary to check for nulls.
That will give information in the gui if the code fails to compile or whatever.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Sorry, I didn't mean to say validator. I am using a simple script condition as you mentioned. The condition tester is showing "false" for both an issue with the correct value and an issue with the incorrect value. When I try a null, I get this error:
javax.script.ScriptException: java.lang.NullPointerException: Cannot invoke method getAt() on null object
I was thinking about adding a validator to ensure that the field cannot be null, but regardless both true and false cases are showing up as false.
This is my condition:
def vals = cfValues["Request Type"]?.allValues
vals[0] == "Retail" && vals[1] == "Add prescriber"
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Things get complicated around cascading selects. Here is the condition:
cfValues.get("Request Type")?.getAllValues()*.value == ['Retail', 'Add prescriber']
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thank you so much! Works perfectly! I appreciate your quick responses and troubleshooting!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You're welcome...
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Jamie,
I tried copying the format for the cascading select condition. But It doesnt seem to work for me.
I also get this error in the server logs
[groovy.canned.utils.ConditionUtils] javax.script.ScriptException: groovy.lang.MissingMethodException: No signature of method: java.util.HashMap.getAllValues() is applicable for argument types: () values: []
What does this mean?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Jamie,
We recently upgraded to Jira 5.1.6, and the Cascade Select Condition you suggested is no longer working. We cannot figure out what the problem is. Can you please advise?
Here is the condition:
cfValues.get("Request Type")?.getAllValues()*.value == ['Retail', 'Add prescriber'] || cfValues.get("Request Type")?.getAllValues()*.value == ['Retail', 'Add new address']
I am getting this error when running the Canned Script Runner:
javax.script.ScriptException: groovy.lang.MissingMethodException: No signature of method: java.util.HashMap.getAllValues() is applicable for argument types: () values: []
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Can you add this to the conditon:
log.warn "Request type: " + cfValues.get("Request Type")?
true
See what it says in the logs and report back pls...
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I am working with someone who has access to the logs in this, and he added this and got the following error:
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Can you post here the full condition. The lines I pasted above should be on new lines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Jamie, thanks for your help. We actually ended up finding the fix. The syntax was changed to:
cfValues.get("Request Type")?.values()*.value == ['Retail', 'Add prescriber'] || cfValues.get("Request Type")?.values()*.value == ['Retail', 'Add new address']
Thanks for your help.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello all!
I was wondering if anyone knows of a way to do this with OnDemand?
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.