Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Why am I getting an error on this jira expression code in a Scriptrunner validator?

Cash Coyne
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.
January 22, 2024

I have this code in a scriptrunner validator:

let TotPoints = 0;
if (issue.customfield_11667 != null) {
let TotPoints = TotPoints + issue.customfield_11667;
};

But when I use it, I get this error:

Jira expression failed to parse: line 4, column 1: let, IDENTIFIER, return, throw, !, -, typeof, (, null, true, false, NUMBER, STRING, TEMPLATE_LITERAL, new, [, {, try or if expected, } encountered.

What am I doing wrong?

4 answers

1 accepted

0 votes
Answer accepted
Maciej Dudziak _Forgappify_
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.
March 5, 2024

I am not sure what tool you are using, but the error message suggests that this is indeed a Jira expression. Then, you will need an else clause and probably return statements inside

However, assuming that TotPoints may differ, I would rewrite it to the following:

let TotPoints = 0;
issue.customfield_11667 != null ? TotPoints + issue.customfield_11667 : TotPoints

 

0 votes
Ram Kumar Aravindakshan _Adaptavist_
Community Champion
January 23, 2024

Hi @Cash Coyne

The approach you have tried will not work. When using the Jira Cloud, the Validator only allows the usage of Jira Expressions. Hence, your code fails.

I suggest referring to this ScriptRunner for Jira Cloud documentation to view the example expressions that can be used for the Validator.

Also, I suggest looking through the ScriptRunner Code snippets for examples of Validator Expression.

Thank you and Kind regards,
Ram

0 votes
Aswin Raj D
Community Champion
January 22, 2024

Hello @Cash Coyne ,

Please try like below

 

import com.atlassian.jira.component.ComponentAccessor

def issue = issue
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def totPointsField = customFieldManager.getCustomFieldObjectByName("Your Custom Field Name") // Replace with the actual name of your custom field

def totPoints = 0

if (issue.getCustomFieldValue(totPointsField) != null) {
    totPoints = totPoints + issue.getCustomFieldValue(totPointsField)
}
Ram Kumar Aravindakshan _Adaptavist_
Community Champion
January 23, 2024

Hi @Aswin Raj D

The sample code you have provided is not applicable for Jira Cloud. This is meant for the Jira Server / DC Environment.

0 votes
Matt Doar
Community Champion
January 22, 2024

Try it without the trailing semicolon on the last line?

Cash Coyne
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.
January 23, 2024

Nope, get this when I drop the trailing semicolon on the last line:

Jira expression failed to parse: line 4, column 1: let, IDENTIFIER, return, throw, !, -, typeof, (, null, true, false, NUMBER, STRING, TEMPLATE_LITERAL, new, [, {, try or if expected, } encountered.

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
PREMIUM
PERMISSIONS LEVEL
Product Admin
TAGS
AUG Leaders

Atlassian Community Events