Our new Appfire Documentation Space is now live!

Take a look here! If you have any questions please email support@appfire.com

Sum up the Story Points in an Epic - BeanShell

Abstract

This code snippet calculates the sum of the story points of all issues in an Epic.

Logic

Iterate over issues in the Epic, and sum up the values of the Story Points custom field.

Snippet 

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

CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager();
CustomField customFieldObject = customFieldManager.getCustomFieldObject("<ID of Story Points custom field>");

Double total = 0;
IssueLinkManager issueLinkManager = ComponentAccessor.getIssueLinkManager();
for (IssueLink outwardLink : issueLinkManager.getOutwardLinks(issueObject.getId())) {
    if (outwardLink.getIssueLinkType().getName().equals("Epic-Story Link")) {
        Double sp = customFieldObject.getValue(outwardLink.getDestinationObject());
        if (sp != null)
            total += sp;
    }
}
return total;

Placeholders

PlaceholderDescriptionExample
<ID of Story Points custom field>The ID of the Story Points custom field, as found on the Custom Fields page.customfield_10008

Examples

This code snippet can be used as the formula of a Calculated Number Field:


<!-- @@Formula:
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.CustomFieldManager;
import com.atlassian.jira.issue.fields.CustomField;
import com.atlassian.jira.issue.link.IssueLink;
import com.atlassian.jira.issue.link.IssueLinkManager;

CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager();
CustomField customFieldObject = customFieldManager.getCustomFieldObject("<ID of Story Points custom field>");

Double total = 0;
IssueLinkManager issueLinkManager = ComponentAccessor.getIssueLinkManager();
for (IssueLink outwardLink : issueLinkManager.getOutwardLinks(issueObject.getId())) {
    if (outwardLink.getIssueLinkType().getName().equals("Epic-Story Link")) {
        Double sp = customFieldObject.getValue(outwardLink.getDestinationObject());
        if (sp != null)
            total += sp;
    }
}
return total;
-->


Filter by label

There are no items with the selected labels at this time.