Hello,
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
import com.atlassian.jira.issue.CustomFieldManager;
import com.atlassian.jira.issue.fields.CustomField;
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.event.type.EventDispatchOption;
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def reopenCountCf = customFieldManager.getCustomFieldObject(18906)
def reopenCount = issue.getCustomFieldValue(reopenCountCf) as Double
reopenCount++
def issueManager = ComponentAccessor.getIssueManager()
def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
issue.setCustomFieldValue(reopenCountCf, reopenCount)
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
at Script26.run(Script26.groovy:10)
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.
Ravi
Hello @Ravi Sagar _Sparxsys_ ,
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?
Regards,
Vidhya
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.