Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Deleted user
0 / 0 points
Next:
badges earned

Your Points Tracker
Challenges
Leaderboard
  • Global
  • Feed

Badge for your thoughts?

You're enrolled in our new beta rewards program. Join our group to get the inside scoop and share your feedback.

Join group
Recognition
Give the gift of kudos
You have 0 kudos available to give
Who do you want to recognize?
Why do you want to recognize them?
Kudos
Great job appreciating your peers!
Check back soon to give more kudos.

Past Kudos Given
No kudos given
You haven't given any kudos yet. Share the love above and you'll see it here.

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

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

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.

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

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 

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Marketplace Apps & Integrations

Why everyone using Jira must be GDPR-compliant

Did you know that penalties up to 4 % of the yearly company turnover are possible in case of GDPR violations? GDPR regulations are currently mainly relevant for companies in the EU, but countries lik...

79 views 1 2
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you