scripted field showing sum of story points left in epic

I have been tasked to create a custom scripted field that will allow a team to see how many story points are left in an epic, so this is only on items to do or in progress. 

 

Does anyone have any idea of the best way to do this. I have looked at other questions on here but am struggling to pull the right information i need to have.

1 answer

Hi Daniel, we also had that problem and one of my colleagues solved it by a new custom field with type "calculated Number field" and following code:

In Short: there is a loop over the linked issues and the value of the field with the story points in it is added to the sum.

Don't know if it is the best way, but it seems to work for us smile

<!-- @@Formula:

import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.fields.CustomField;
import com.atlassian.jira.issue.CustomFieldManager;
import com.atlassian.jira.issue.link.IssueLink;

double sumCustomFieldValues( linkedIssues, customFieldId, linkTypeId ) {
double sum = 0;

CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager();
CustomField customField = customFieldManager.getCustomFieldObject(customFieldId);

for( int i = 0; i < linkedIssues.size(); i++ ){
IssueLink link = linkedIssues.get(i);

if( link.getIssueLinkType().getId() == linkTypeId ){
String currentStatusName = link.getDestinationObject().getStatusObject().getSimpleStatus().getName();
if(!"Cancelled".equals(currentStatusName) && !"Closed".equals(currentStatusName)){
Double customFieldValue = link.getDestinationObject().getCustomFieldValue(customField);
sum += (customFieldValue == null) ? 0 : customFieldValue;
}
}

}


return sum;
}

sumCustomFieldValues(issue.get("issuelinks"), 10002, 10200);

-->

Suggest an answer

Log in or Sign up to answer
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Julia Dillon
Posted Tuesday in Jira

Tell us how your team runs on Jira!

Hey Atlassian Community! Today we are launching a bunch of customer stories about the amazing work teams, like Dropbox and Twilio, are doing with Jira. You can check out the stories here. The thi...

174 views 1 17
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