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!
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
issue.portfolioChildIssues?.sum { it.get("Story Points", 0) }
This should actually work for both.
David
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi, I'm also trying to sum the story points and show the total on Epics via scripted fields. Did you get this working??
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.