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

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

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

Suggest an answer

Log in or Sign up to answer
1 vote
Answer accepted
Jack Nolddor _Sweet Bananas_
Marketplace Partner
Marketplace Partners provide apps and integrations available on the Atlassian Marketplace that extend the power of Atlassian products.
Oct 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

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_
Marketplace Partner
Marketplace Partners provide apps and integrations available on the Atlassian Marketplace that extend the power of Atlassian products.
Oct 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

Ah - that should have been obvious! Thanks.

0 votes
Answer accepted
Peter-Dave Sheehan
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Oct 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'
Peter-Dave Sheehan
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Oct 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.

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