Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,368,217
Community Members
 
Community Events
168
Community Groups

ScriptRunner issues on conditions

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

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

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;.

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

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.

 

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

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,

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

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

Thanks Vladimir.

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
STANDARD
PERMISSIONS LEVEL
Site Admin
TAGS

Atlassian Community Events