How to re-write this query

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:

com.onresolve.jira.groovy.canned.workflow.validators.SimpleScriptedValidato
r
  None:1
    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

This widget could not be displayed.

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. 

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?

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 - http://groovy-lang.org/operators.html#_safe_navigation_operator


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 - http://groovy-lang.org/operators.html#_spread_operator

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
Atlassian Summit 2018

Meet the community IRL

Atlassian Summit is an excellent opportunity for in-person support, training, and networking.

Learn more
Community showcase
Posted Wednesday in New to Jira

Are you planning to trial, or are currently trialling Jira Software? - We want to talk to you!

Hello! I'm Rayen, a product manager at Atlassian. My team and I are working hard to improve the trial experience for Jira Software Cloud. We are interested in   talking to 20 people planning t...

135 views 2 0
Join discussion

Atlassian User Groups

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

Find a group

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

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you