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

This widget could not be displayed.

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
Atlassian Summit 2018

Meet the community IRL

Atlassian Summit is an excellent opportunity for in-person support, training, and networking.

Learn more
Community showcase
Posted Wednesday in New to Jira

Are you planning to trial, or are currently trialling Jira Software? - We want to talk to you!

Hello! I'm Rayen, a product manager at Atlassian. My team and I are working hard to improve the trial experience for Jira Software Cloud. We are interested in   talking to 20 people planning t...

281 views 5 0
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