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

Listener not updating fields on transition screen

I have a parent issue and a sub-task which both share a screen. I have created a custom listener which updates the fields when it is edited on the edit screen, but it does not work when it is updated on the transition screen. The listener listens to the 'Issue Updated' event, and I have configured the workflow transition post functions so that this event is fired here.

I read somewhere that this may be an event problem, but I am not sure what I am doing wrong. The code is as below:

import com.atlassian.jira.event.issue.IssueEvent
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.type.EventDispatchOption

def customFieldManager = ComponentAccessor.getCustomFieldManager()
def issueManager = ComponentAccessor.getIssueManager()
def changeHistoryManager= ComponentAccessor.getChangeHistoryManager()
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def issue = event.getIssue()

if(issue.issueTypeObject.name == "Joiner Information" || issue.issueTypeObject.name == "Leaver Information"){
//get the parent issue
def parentIssue = issue.parentObject
//get all the custom fields
def customFields = customFieldManager.getCustomFieldObjects(issue)

//get the changed item list from change log
def changeLogs = event.getChangeLog()
def changedItem = changeHistoryManager.getAllChangeItems(issue).findAll { it.changeGroupId == changeLogs.id}

//mutating parent issue
def mutableParentIssue = issueManager.getIssueObject(parentIssue.id)
//update parent issue if the changed item is a custom field
changedItem.each { item ->;
if(customFields*.name.contains(item.field)) {
def customFieldName = item.field
def customField = customFieldManager.getCustomFieldObjectByName(customFieldName)
def customFieldValue = issue.getCustomFieldValue(customField)
mutableParentIssue.setCustomFieldValue(customField, customFieldValue)
}
}
//updating the parent issue only if condition is true
if(mutableParentIssue.getModifiedFields()){
issueManager.updateIssue(user, mutableParentIssue, EventDispatchOption.ISSUE_UPDATED, false);
}
}

I get the following error:

 

2019-02-04 13:18:28,739 ERROR [runner.AbstractScriptListener]: *************************************************************************************
2019-02-04 13:18:28,739 ERROR [runner.AbstractScriptListener]: Script function failed on event: com.atlassian.jira.event.issue.IssueEvent, file: <inline script>
java.lang.NullPointerException: Cannot get property 'id' on null object
	at Script2091.run(Script2091.groovy:22)
	at com.onresolve.scriptrunner.runner.ScriptRunnerImpl.runScriptAndGetContext(ScriptRunnerImpl.groovy:173)
	at com.onresolve.scriptrunner.runner.ScriptRunner$runScriptAndGetContext$2.callCurrent(Unknown Source)
	at com.onresolve.scriptrunner.runner.ScriptRunnerImpl.runStringAsScript(ScriptRunnerImpl.groovy:162)
	at com.onresolve.scriptrunner.runner.ScriptRunner$runStringAsScript$5.call(Unknown Source)
	at com.onresolve.scriptrunner.canned.jira.workflow.listeners.CustomListener.doScript(CustomListener.groovy:123)

 

0 answers

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Marketplace Apps & Integrations

Staying organized with Jira: best practices for a better project management

Project managers know this problem: A “mountain of work” lays in front of you, and you don’t know how and where to tackle them. Different to-dos lie ahead, but just one task after the other can be ha...

274 views 2 1
Read article

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