Forums

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

Why this script field is not working in scriptrunner HAPI for Jira Cloud

Michael Zhou
February 3, 2026

It seems the expression ‘preewalue = preewalue + 1’ is not working in scriptrunner for Jira Cloud, the error pls refer to the picture, thanks.


def eventissue = Issues.getByKey(issue.key as String)
Long reopencountfieldId = 10883
if(eventissue){
def preewalue = eventissue.getCustomFieldValue(reopencountfieldId)
preewalue = preewalue + 1
eventissue.update {
setCustomFieldValue(reopencountfieldId, preewalue)
}
}reopen1.jpg

2 answers

0 votes
Kristian Walker _Adaptavist_
Community Champion
February 4, 2026

Hi Michael,

The static type checking error you get is due to the fact that the compiler does not recognise the type in the line preewalue = preewalue + 1, but you can fix this by changing the line to preewalue = preewalue as Integer + 1 to specify the type is an integer.

However, this use case for your script is not the correct use case for a script field as Scripted Fields in Jira cloud must return a value and update  the scripted field they create as documented here

I would advise making this a Script Listener that runs on the issue updated event and then this script will work. 

I tested your code as a Script Listener on the issue updated event and it worked as expected. 

If you need further help creating the script then please raise a request here with the ScriptTunner support team who can assist you with this.

Regards,

Kristian 

0 votes
Trudy Claspill
Community Champion
February 3, 2026

Hello @Michael Zhou 

You are getting that error because in the first line of your code you are not providing an actual issue key. You need to provide an actual issue key; i.e.

def eventissue = Issues.getByKey("ABC-123")

issue.key as String indicates the type of input that has to be provided. You need to replace that with an actual appropriate value.

Michael Zhou
February 3, 2026

Thanks Trudy,

This script field is for all projects if the screen add it, not for the dedicated project, could you tell me how to write the script? thank you very much.

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