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

ScriptRunner issues on conditions

Shawn Marks
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
August 20, 2020

Trying to have scriptrunner listener run on jira cloud but only if the issue has a label matching "foo". I have the following but just get an error:

("foo" in issue.fields.labels)

2020-08-20 20:13:45.395 ERROR - The condition: ("foo" in issue.fields.labels) evaluated to: ["Jira expression failed to parse: line 1, column 19:\nexpression expected, reserved keyword 'in' encountered."]

1 answer

Suggest an answer

Log in or Sign up to answer
0 votes
Kristian Walker _Adaptavist_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
August 21, 2020

Hi Sean,

I can confirm that the ScriptRunner for Jira Cloud plugin provides Evaluate Condition feature for Script Listeners using the Jira Expression Framework as documented in the Atlassian API documentation page located here or in the documentation page located here.

We can confirm that when viewing the Jira Expression Framework API documentation page linked above you can navigate to the Context variables section which shows what variables are provided by this framework that can be used to create the expression.

If you then click on one of the variables it will show all the properties that can be called on the variable for the expression such as for the issue variable as shown here.

I can confirm that this shows the labels field is a List type which means it only supports being accessed using the methods documented in the expression API documentation page located here.

I can confirm based on this I have created the example located here which shows on line 18 the expression to check when the label field includes a specified label.

I would recommend using these documentation pages linked above as a reference guide to help to create the condition expression that you require.

I hope this information helps.

Regards,

Kristian

Vladimir Virlan September 15, 2021

Hey Kristian, 

Thanks for your answer. However, I am having the same problem only this time with a different keyword: `let`.

 

For this script:

let a = 1;

I get:

"Jira expression failed to parse: line 1, column 30:\nexpression expected, reserved keyword 'let' encountered."

 

The guide you quoted specifically allows variable declarations:

https://developer.atlassian.com/cloud/jira/platform/jira-expressions/#variable-assignment

 

A Jira expression can be defined as a series of variable assignments ending with an expression, each separated by a semicolon. For example, this expression returns a String containing the number of comments on an issue:

let issueKey = issue.key;
  let commentsLength = issue.comments.length;
  `Issue ${issueKey} has ${commentsLength} comments.`

The let keyword is optional. For example, line 1 of the example can be written as issueKey = issue.key;.

Oliver Siebenmarck _Polymetis Apps_
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.
September 16, 2021

Hi @Vladimir Virlan ,

The problem really isn't the let keyword, it's that your code does not contain an expression. Let me explain that a bit:

Jira expressions are meant to be evaluated to a value, like these values:

true
6
"PROJ-12"
{'foo': 1, 'bar': 2}

Typically the return value of the last expression of an expression's code is taken as the result. So you could write this:

user.displayName

Or this:

let a = 1;
a

And it would be perfectly valid and return 1. However, just this:

let a = 1;

does not evaluate to anything, as the let statement does not have a return value. That's why you get that "expression expected" error message. 

Hope that helps,
 Oliver

Vladimir Virlan September 16, 2021

Thanks @Oliver Siebenmarck _Polymetis Apps_ however that was just a simplification and I ommitted the return fragment.

 

This also doesn't work:

 

"use strict"
let a = true;
a;

 

Yo usee here the value of `a` is the resulting expression and we should see the whole thing return true. However it fails with the same error:

 

Jira expression failed to parse: line 2, column 1: expression expected, reserved keyword 'let' encountered.

 

Oliver Siebenmarck _Polymetis Apps_
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.
September 16, 2021

Hi @Vladimir Virlan 

I see, thanks for the clarification. I don't think "use strict" is a thing with Jira expressions – even though they look like JavaScript they aren't a 100% the same. So, this produces an error:

"use strict"
let a = true;
a;

So does this:

"hello"
"foo"
5

The reason is, that you can only have one value that your expression evaluates to. So, going back to your example, you should be able to do something like this:

<let_statement>
<let_statement>
<let_statement>
<let_statement>
<expression>

but not this:

<expression>
<let_statement>
<expression>

Hope that helps. Let me know if you have a more specific use-case/example.

Best regards,
  Oliver

Vladimir Virlan September 16, 2021

Many thanks @Oliver Siebenmarck _Polymetis Apps_ for following up on this. I think I must explain why I added "use strict". 

 

My initial problem is this: I am writing the expressions on the Workflow validators page in ScriptRunner. There is a Test functionality so that you provide a jira id and it would validate the script against that jira item. Now, this works using Test:

 

screenA.PNG

However, this script fails when I actuall save this validator and go to that jira and move it from one status to another to trigger this validator. And it fails with the error shown. Now, I've discovered that by using "use strict" we can emulate the same error using the Test button:

 

screenB.PNG

 

Now that you answered, I can see that it's not about "use strict", but any string could go there and it make it fail.

 

So I believe, something is inserting an empty line when I transition the jira from one status to another and it fails, while passing the Test against functionality..

Thanks,

Kalpesh
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
February 5, 2022

Thanks @Vladimir Virlan - I am also having same issue with scriptrunner conditions, can you please share any workaround or fix, if any.

Vladimir Virlan February 7, 2022

@kalpesh just keep the jira expressions simple - one liners. There is no known workaround. 

Kalpesh
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
February 7, 2022

Thanks Vladimir.

DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
STANDARD
PERMISSIONS LEVEL
Product Admin
TAGS
AUG Leaders

Atlassian Community Events