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
Community showcase
Posted Sep 18, 2018 in Jira

What modern development practices are at the heart of how your team delivers software?

Hey Community mates! Claire here from the Software Product Marketing team. We all know software development changes rapidly, and it's often tough to keep up. But from our research, we've found the h...

25,431 views 2 7
Join discussion

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