I've a script placed in 'post function' of 'reopen' transition to increase the counter of 'Reopen Count' field. It works sometimes but other times it throws null pointer exception
Below is the script
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def reopenCountCf = customFieldManager.getCustomFieldObject(18906)
def reopenCount = issue.getCustomFieldValue(reopenCountCf) as Double
def issueManager = ComponentAccessor.getIssueManager()
def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
issueManager.updateIssue(currentUser, issue, EventDispatchOption.DO_NOT_DISPATCH, false)
The error that I get is
2021-06-07 14:12:06,115 ERROR [workflow.AbstractScriptWorkflowFunction]: Workflow script has failed on issue E2ET-45536 for user 'xxx'. View here: https://jiraprd-proximuscorp.msappproxy.net/secure/admin/workflows/ViewWorkflowTransition.jspa?workflowMode=live&workflowName=0_e2e_bug_wf&descriptorTab=postfunctions&workflowTransition=331&highlight=1
java.lang.NullPointerException: Cannot invoke method next() on null object
What is wrong with my code?
Does it fail when there is no value in the custom field? If yes may be you can try to add a check if the custom field value is null (empty) then instead of doing reopenCount++ just try to update the field value with 1.
I hope it works.
Hello @Ravi Sagar ,
You are right.. When the value is null it is failing. If the value is 0 or something else, then it is working correct. I'm new to groovy scripting. The script above I got it from atlassian forum. Would it be possible for you to help me with the changes that needs to be made to the script?
Connect with like-minded Atlassian users at free events near you!Find an event
Connect with like-minded Atlassian users at free events near you!
Unfortunately there are no Community Events near you at the moment.Host an event
You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events