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

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,461,523
Community Members
 
Community Events
176
Community Groups

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

1 vote

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

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?

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.

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

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

Suggest an answer

Log in or Sign up to answer
TAGS

Atlassian Community Events