Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Deleted user
0 / 0 points
Next:
badges earned

Your Points Tracker
Challenges
Leaderboard
  • Global
  • Feed

Badge for your thoughts?

You're enrolled in our new beta rewards program. Join our group to get the inside scoop and share your feedback.

Join group
Recognition
Give the gift of kudos
You have 0 kudos available to give
Who do you want to recognize?
Why do you want to recognize them?
Kudos
Great job appreciating your peers!
Check back soon to give more kudos.

Past Kudos Given
No kudos given
You haven't given any kudos yet. Share the love above and you'll see it here.

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

script for Counting how many times a bug was reopened throws null pointer exception

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? 

1 answer

1 accepted

0 votes
Answer accepted
Ravi Sagar Community Leader Jun 07, 2021

Hi @Vidhya Mohan 

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 ,

 

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

Suggest an answer

Log in or Sign up to answer
TAGS

Community Events

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

Events near you