Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

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Ā 

Code Block
languagejs
linenumberstrue
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() == "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:

...

Code Block
languagejs
linenumberstrue
<!-- @@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() == "Epic-Story Link") {
        Double sp = customFieldObject.getValue(outwardLink.getDestinationObject());
        if (sp != null)
            total += sp;
    }
}
return total;
-->


Filter by label (Content by label)
showLabelsfalse
max5
spacesKB
showSpacefalse
sortmodified
reversetrue
typepage
cqllabel = "jmwe-groovy" and type = "page" and space = "KB"
labelsjmwe-nunjucks jmwe-cloud

...