Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Where can I find scriptrunner documentation that defines the syntax and field names

Tim Wright October 28, 2019

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? 

2 answers

2 accepted

Suggest an answer

Log in or Sign up to answer
1 vote
Answer accepted
Jack Nolddor _Sweet Bananas_
Atlassian Partner
October 28, 2019

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

Tim Wright October 29, 2019

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.

Jack Nolddor _Sweet Bananas_
Atlassian Partner
October 29, 2019

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

Like Tim Wright likes this
Tim Wright October 29, 2019

Ah - that should have been obvious! Thanks.

0 votes
Answer accepted
PD Sheehan
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 28, 2019

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'
PD Sheehan
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 28, 2019

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.

Tim Wright October 29, 2019

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.

TAGS
AUG Leaders

Atlassian Community Events