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)
}
}
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
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.