Are you in the loop? Keep up with the latest by making sure you're subscribed to Community Announcements. Just click Watch and select Articles.

×
Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Celebration

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Sum of Story Points in Epic - scripted field

I'm trying to implement the scripted field per the discussion here: https://community.atlassian.com/t5/Jira-questions/Scripted-field-sum-of-story-points-of-linked-issues-only-with/qaq-p/33025

And the script I'm using looks like:

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_11662");

if (issue.getIssueTypeId() != 6) {
return null
}
issueLinkManager.getOutwardLinks(issue.id)?.each {issueLink ->;
if (issueLink.issueLinkType.name == "Epic-Story Link" ) {
double SP = (double)(issueLink.destinationObject.getCustomFieldValue(customField) ?: 0)
totalSP = SP + totalSP;
}}
return totalSP

-----------------

The Story Points field ID is 11662, and the issue type ID for Epic is 6. 

The script compiles and runs, but always returns null. For some reason, logging does not work for this script, so I'm kind of flying blind. Anyone see anything obvious?

Thanks!

3 answers

Suggest an answer

Log in or Sign up to answer
1 vote
Pete Singleton
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
Nov 02, 2019

I managed to get this working (using JMCF add-on) as follows:

 

import com.atlassian.jira.ComponentAccessor
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.component.ComponentAccessor;

def issueLinkManager = ComponentAccessor.getIssueLinkManager()
def cfManager = ComponentAccessor.getCustomFieldManager()

double totalSP = 0
customField = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Story Points");
enableCache = {-> false}

issueLinkManager.getOutwardLinks(issue.id)?.each {issueLink ->
if (issueLink.issueLinkType.name == "Epic-Story Link" ) {
int SP = (int)(issueLink.destinationObject.getCustomFieldValue(customField) ?: 0)
log.debug("Story Points : "+ SP);
log.debug("Issue :" + issueLink.getDestinationObject().getKey() );
totalSP = SP + totalSP;
}}

return totalSP
David Fischer _Appfire_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Nov 02, 2019

Note that this is with JMCF 1.7.  In JMCF 2, it would be one line of code. 

Could you tell me what that line of code would be?

David Fischer _Appfire_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Dec 27, 2019

Sure:

issue.stories?.sum { it.get("Story Points", 0) }

Be aware, though, that the "Story Points" field might be called differently on your instance (such as "Story points" - lowercase "p"). The safest is to use the custom field ID instead of name, which is accessible from the "Issue Fileds" help tab of the formula editor.

What would the equivalent JMCF code be for summing up the story points in an Initiative that contains Epics with story points?

Ideally, I would have one formula that works for either Initiatives or Epics, so I don't have to create a new context for the two issue types.

David Fischer _Appfire_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Dec 13, 2021
issue.portfolioChildIssues?.sum { it.get("Story Points", 0) }

This should actually work for both.

David

Like Chris Melville likes this

Thank you for the response.  It does work for Initiatives and other Portfolio hierarchy issue types, but does not work for Epics, even though they are defined in the hierarchy.  I can solve for both by simply combining the two.

Not sure, but maybe something wrong with typeID or feldID. Could you try this:




//Scripted Fields
//Field name : StoryPointsSum
//Field Description : Sum of Story Points in Epic
//Default Configuration Scheme for Count of Open Stories
//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().getCustomFieldObjectByName("Story Points");

if (issue.getIssueType().getName() != "Epic") {
return null
}

issueLinkManager.getOutwardLinks(issue.id)?.each {issueLink ->


if (issueLink.issueLinkType.name == "Epic-Story Link" ) {
totalSP += (double)(issueLink.destinationObject.getCustomFieldValue(customField) ?: 0)
}
}

return totalSP 
0 votes
Pete Singleton
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
Jul 17, 2019

Hi, I'm also trying to sum the story points and show the total on Epics via scripted fields.  Did you get this working??

TAGS
AUG Leaders

Atlassian Community Events