Scripted field to sum story points of issues linked to an epic in closed status

I am trying to create a scripted field that will sum the story points of issues linked to an epic that are in closed status.

JIRA version: 7.1.6 server

Scriptrunner version: 4.3.12

Searcher: Number searcher

Template: Number field

import com.atlassian.jira.ComponentManager
import com.atlassian.jira.ComponentAccessor
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.component.ComponentAccessor;
def componentManager = ComponentManager.getInstance()
def issueLinkManager = ComponentAccessor.getIssueLinkManager()
def cfManager = ComponentAccessor.getCustomFieldManager()
double totalSP = 0
customField = ComponentAccessor.getCustomFieldManager().getCustomFieldObject("customfield_12110");
enableCache = {-> false}

issueLinkManager.getOutwardLinks(issue.id)?.each {issueLink ->
if ((issueLink.issueLinkType.name == "Epic-Story Link" ) && (issue.getStatus() == "Closed")){
double SP = (double)(issueLink.destinationObject.getCustomFieldValue(customField) ?: 0)
totalSP = SP + totalSP;
}}
return totalSP

It is returning a result of 0. 

I am new to scripted fields and need help troubleshooting. Thanks!

1 answer

Hi Colleen,

I think what you miss (apart form the first import that does not exist) is the 

issue.getStatus() == "Closed"

it should be 

issue.getStatus().name == "Done" 
// or if you need the category and not just the name of the status
issue.getStatus().statusCategory.name == "Closed"

apart from that your script seems fine. And one more thing, I suppose the customfield_12110 is the Story Points, wouldn't be more clear If it was 

def customField = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Story Points")


regards, Thanos

Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published Monday in Jira Software

How large do you think Jira Software can grow?

Hi Atlassian Community! My name is Shana, and I’m on the Jira Software team. One of the many reasons this Community exists is to connect you to others on similar product journeys or with comparabl...

620 views 6 12
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you