I am just starting to use scriptrunner workflow validator functions and I am finding that the examples in the scriptrunner documentation get you so far, but don't answer all the questions.
For example, using Simple Scripted Validator, the example suggests the following for "Has select list value equal to":
cfValues['My Select List']?.value == 'My value'
I am trying to check that the contents of my custom field "Project Version" (which is a Version Picker (single version) field type) contains particular values before the transition is allowed.
So, based on the example I started with:
cfValues['Project Version']?.value == 'CURRENT'
but this has syntax errors. After a lot of searching on Google and trial and error, I managed to find the solution:
'CURRENT' in cfValues['Project Version']*.name
I have been searching for a reference guide which tells me the syntax and type definitions but I can't find such a thing in the scriptrunner documentation - can anyone point me in the right direction please?
Hi Tim,
You must have a look to:
1.- The groovy language itself
2.- The Jira Java API
3.- The oficial Script Runner documentation
In addition, you will find handy examples at Adaptavist Library
Hope this helps,
Regards
Hi Jack,
Thank you for this information - very helpful, especially the link to the Jira Java API. I notice that is to version 7.2.1, but there are later versions available. Is there a way I can tell which version I should be looking at? (I am on Jira server v7.13.5).
Tim.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Sure, simply replace the version in the URL directly.
ie:
https://docs.atlassian.com/software/jira/docs/api/7.13.5/allclasses-noframe.html
Regards
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.
cfValues['Project Version'] will return an object of the type that corresponds to the type of field.
For a single select, it would be an Option.
But for a version picker, then it would be a Version
And for version, the "getValue()" method is invalid.
The reason why 'CURRENT' in cfValues['Project Version']*.name does work is because , as you stated, Project Version is a "Single Version picker". That syntax would be appropriate for a "Multi Version picker".
All "multi" type fields, return an array of objects of the appropriate type (option, user, version etc). And the "x in object*.attribute" only works if the object is an array
So try
cfValues['Project Version']?.name == 'CURRENT'
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Additionally, what helps me in those cases, if I'm not sure what type of object a scriptrunner binding might contain (and it's hard to document as it will depend), is to examine the class name and look up the documentation or examine the full list of methods to see which might be appropriate.
You can try some debug messages like:
log.debug cfValues['Project Version'].getClass()
log.debug cfValues['Project Version'].metaClass.methods*.name.sort().unique()
If the first returns "ArrayList", then try:
log.debug cfValues['Project Version'][0].getClass()
log.debug cfValues['Project Version'][0].metaClass.methods*.name.sort().unique()
Then you will see "com.atlassian.jira.project.version.VersionImpl" ... and you can go look that up.
The second will get you something like:
[copyDate, equals, getClass, getDescription, getId, getName, getProject, getProjectId, getProjectObject, getReleaseDate, getSequence, getStartDate, hashCode, isArchived, isReleased, notify, notifyAll, toGenericValue, toString, wait]
That can give you a clue of what's available.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Peter-Dave,
Thank you - this is very helpful, particularly the debug output instructions.
I think I shall be able to make progress now.
Many thanks,
Tim.
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.