Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Scripted field for total Story Points from linked issues

Matthew_Schulz July 24, 2019

I'm trying to get the total number of Story Points from Linked Issues (is Feature of) onto a custom scripted field on a Feature. Here's the code:

 

import com.atlassian.jira.component.ComponentAccessor;

enableCache = {-> false}
def issueLinkManager = ComponentAccessor.getIssueLinkManager()
def totalSP = 0.0
log.debug("${customField.id}")

log.debug("Issue ${issue}")
issueLinkManager.getIssueLinks(issue.id)?.each {issueLink ->
if (issueLink.issueLinkType.name == 'is Feature of') {
customField = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Story Points")
def SP = issueLink.destinationObject.getCustomFieldValue(customField) as Double ?: 0.0
log.debug("SP value ${SP}")
totalSP += SP
}}

return totalSP as Double

 

This worked for getting the total Story Points from Epic Links, but doesn't work currently.

 

Please help!

 

Thanks,

Matt

1 answer

0 votes
Lady Di
Atlassian Partner
July 24, 2019

Written for Mygroovy, but maybe with other similar plugins will work.

 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.search.SearchProvider
import com.atlassian.jira.jql.parser.JqlQueryParser
import com.atlassian.jira.web.bean.PagerFilter

//issue = ComponentAccessor.getIssueManager().getIssueObject("ISSUE-123")
//return 0
issuetypes = [epic: "Epic"]
fields = [storyPoints: 15402L, epicName: 15501L]
issuetype = issue.getIssueType().getName()

if (issue.isSubTask()) {
return getCustomFieldValue(issue, fields.storyPoints) ?: 0
}
storyPoints = []
storyPoints += getCustomFieldValue(issue, fields.storyPoints) ?: 0
if (issuetype == issuetypes.epic) {
epicName = getCustomFieldValue(issue, fields.epicName)
issuesInEpic = _.getIssuesByJQL("'Epic Link' = '${epicName}'")
storyPoints += issuesInEpic.collect{getStoryPointsFromSubtasks(it)}
storyPoints += issuesInEpic.collect{getCustomFieldValue(it, fields.storyPoints) ?: 0}
}
else {
storyPoints += getStoryPointsFromSubtasks(issue)
}
storyPoints = storyPoints - null
return storyPoints.sum() ?: 0


def getStoryPointsFromSubtasks(parentIssue) {
def sp = parentIssue?.getSubTaskObjects()?.collect{getCustomFieldValue(it, fields.storyPoints) ?: 0}?.sum()
return sp ?: 0
}

def getCustomFieldValue(issue, Long fieldId) {
issue.getCustomFieldValue(ComponentAccessor.getCustomFieldManager().getCustomFieldObject(fieldId))
}
Matthew_Schulz July 24, 2019

Thanks for the quick response! But I need to get the total Story Points onto a 'Feature' issue type's custom scripted field. This seems to work for one issue in an Epic?

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events