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

How to re-write this query

Larry Gadallah Jul 12, 2016

We recently upgraded from JIRA 5.x to 7.x, and concurrently, went to the 4.3.4 version of the ScriptRunner for JIRA plugin. Once this happened, we started seeing failures with Simple scripted validator scripts such as the following:

  • cfValues['Story Points'].toInteger() in [1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233]
  • cfValues['Actual Points'].toInteger() > 0

I found, to my surprise that in the former case, simply removing the .toInteger() seemed to make the script editor happy, even though the Script registry still complains with errors like this:

    No context set for compile @ line 1, column 1.

I note that the release notes from Atlassian and Adapavist both indicate that something needs to change after the upgrade, but I can't figure out what's involved (short of possibly installing a full Groovy development environment, which I'd like to avoid).

1 answer

0 votes
Chris Solgat Jul 13, 2016

For the most part, the Groovy changes that need to be made should not affect much of the "built-in" functionalities like the Simple Script Validator.  That being said, from ScriptRunner's documentation, it looks like you may want to change the toInteger() to value.  Here is the link to the documentation for Simple Scripted Validators Examples.
As far as the error that shows up in the Script Registry, the context refers to the Issue that would be going through the workflow.  Since the Script Registry is doing a Static Compilation and doesn't modify any data/issues, it does not have an Issue to reference for it's context. 

Larry Gadallah Jul 13, 2016

I had seen the documentation for the examples for Simple Scripted Validators, but I was frustrated that our two use cases (custom field value, as an integer, is a member of a set of integers; and custom field value, as an integer, is greater than zero) do not seem to be represented there.

Regarding the "value" method, I see that there are examples such as cfFields['foobar']?.value and cfFields['foobar']*.value. What is the meaning/purpose of the ? and * in these examples?

Chris Solgat Jul 13, 2016

The short answer is that they are used to handle Null Pointer Exceptions by returning a null value instead.  The " ? " is for a single item and the " * " is used for iterative items (lists, arrays, etc...).

Here are the full definitions and the referenced links:
The Safe Navigation operator is used to avoid a NullPointerException. Typically when you have a reference to an object you might need to verify that it is not null before accessing methods or properties of the object. To avoid this, the safe navigation operator will simply return null instead of throwing an exception.
ref -

The Spread Operator (*.) is used to invoke an action on all items of an aggregate object. It is equivalent to calling the action on each item and collecting the result into a list.
The spread operator is null-safe, meaning that if an element of the collection is null, it will return null instead of throwing a NullPointerException.
The spread operator can be used on any class which implements the Iterable interface.
ref -

Larry Gadallah Jul 14, 2016

If I change my simple scripted validator to

cfValues['Story Points'].toInteger() in [0, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233]

I get the error "[Static type checking] - Cannot find matching method java.lang.Object#toInteger().

If I change it to

cfValues['Story Points']?.value in [0, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233]

I get the error "[Static type checking] - No such property: value for class: T

If I change it to


cfValues['Story Points'] in [0, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233]

it seems happy, but then the following validator is broken

cfValues['Actual Points'].toInteger() >= 0

I can make it work by using

cfValues['Actual Points' != 0

but that doesn't really solve my problem (I want it to succeed only if the Actual Points are a real, positive integer.

Suggest an answer

Log in or Sign up to answer
This widget could not be displayed.
This widget could not be displayed.
Community showcase
Posted in Jira Software

Demo Den Ep. 5: Meet Jira Mobile

See how to use Jira on the go! Demo Den Episode 5 is here: meet Jira Mobile with  Jira  Product Manager Rayen Magpantay.  Demo Den is in our monthly series where a Jira PM demonstrates...

315 views 1 10
Join discussion

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