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
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))
}
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?
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.