Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
Community Members
Community Events
Community Groups

update epic story points when story in epic updated


Hi. I am trying to create a listener to run whenever the "story point" field for non-epic issues are updated. I would like the listener to get the issue epic link and then run through all the issues in that epic summing up the story points and then write that to the epic story point field. 

I have used a mish mash of cut and pastes from various posts and come up with this .. but it doesnt work .. there is no failure and  no information so i can not see what is going wrong. I dont know how to use preview in listener so can really test it. Any advice or suggestions would be much appreciated:


import com.atlassian.jira.component.ComponentAccessor
import groovy.xml.MarkupBuilder
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.fields.CustomField;

import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder

//get issue
def issue = event.issue as Issue

//now get epic

def customFieldManager = ComponentAccessor.getCustomFieldManager()

//def epicLinkCf = customFieldManager.getCustomFieldObjectsByName("Epic Link")
def epicLinkCf = customFieldManager.getCustomFieldObjects(event.issue).find { == "Epic Link"}

def epicIssue = issue.getCustomFieldValue(epicLinkCf) as Issue

if (epicIssue) {
// (epicIssue.getCustomFieldValue(epicCustomField))

def epicCustomField = customFieldManager.getCustomFieldObjectsByName("Story Points") //change to your Epic custom field's name

//now get story points of issues in epic
def issueLinkManager = ComponentAccessor.getIssueLinkManager()
def links = issueLinkManager.getOutwardLinks(

def writer = new StringWriter()
def xml = new MarkupBuilder(writer)
def cfManager = ComponentAccessor.getCustomFieldManager()

def cfStoryPoints = cfManager.getCustomFieldObjects().find{ == "Story Points"}
def cfStoryPointsTotal = 0


links.each {issueLink ->

if ( == "Epic-Story Link") {
def linkedIssue = issueLink.destinationObject

cfStoryPointsTotal = cfStoryPointsTotal += linkedIssue.getCustomFieldValue(cfStoryPoints) ?: 0




// write the total values to the epic
def changeHolder = new DefaultIssueChangeHolder()
// get epic story points field

def tgtEpicField = customFieldManager.getCustomFieldObjects(epicIssue).find { == "Story Points"}

tgtEpicField.updateValue(null, issue, new ModifiedValue(epicIssue.getCustomFieldValue(tgtEpicField), cfStoryPointsTotal ),changeHolder)

1 answer

Easiest is to add log info in your script...

There is no issue update (save the issue) in your script ? (nor a re-index of the issue ?)...

But... why having a field updated by listeners ? Isn't a scripted field on the Epic much easier (no worry about saving, indexes, ...)?

Code might be something like (did not add the import stuff)

IssueLinkManager issueLinkManager = ComponentAccessor.getIssueLinkManager()
CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager()

CustomField cfSPts = customFieldManager.getCustomFieldObjectByName("Story Points")
BigDecimal storyPoints
issueLinkManager.getOutwardLinks(issue.getId()).each {epicLink ->
if (epicLink.getIssueLinkType().getName() == "Epic-Story Link") {
Issue epicLinkedIssue = epicLink.getDestinationObject()
if (epicLinkedIssue.getCustomFieldValue(cfSPts)) {
if (!storyPoints) {storyPoints = 0.0}
storyPoints += (BigDecimal) epicLinkedIssue.getCustomFieldValue(cfSPts)
if (storyPoints) {
return storyPoints.toDouble()
} else {
return null

Thanks Marc . I will check out your script tomorrow when back at work but I just wanted to reply to your question : "But... why having a field updated by listeners ? Isn't a scripted field on the Epic much easier (no worry about saving, indexes, ...)?"

The reason I wanted a field update listener is so that the epics story point value will be updated as soon as an issue (in the epic) story point value is updated .. and so can be used in a report or when someone looks at the epic kanban board straight away 

I thought that if i used a scripted field then it would require someone to open / view the epic before the epics story point field was recalculated .. 

is my assumption wrong ? ie if i use a scripted field will the epic story point summation be updated without having to open the epic ? 

thanks again 

We use a lot scripted fields, and they are correctly updated everywhere in Jira (Reports, Boards, other plugins, even in REST calls to Jira) !

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted in Jira Service Management

Jira Service Management Documentation Opportunities

Hello everyone, Hope everyone is safe! A few months ago we posted an article sharing all the new articles and documentation that we, the AMER Jira Service Management team created. As mentioned ...

298 views 0 9
Join discussion

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