Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

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

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

1 vote
Answer accepted

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.

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

Ah - that should have been obvious! Thanks.

0 votes
Answer accepted

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'

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.

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.

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Statuspage

New feature: Slack notifications for Statuspage

We're excited to announce the release of a long-requested feature on Statuspage. Now visitors to your status page can subscribe to get notified in Slack when you report an incident or maintenance. Th...

51 views 0 8
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you