https://library.adaptavist.com/entity/calculate-the-sum-of-all-values-of-a-custom-field-in-linked-issues
Is anyone else getting an error when trying to use this code? I found it in the
library
import com.atlassian.jira.component.ComponentAccessor
def issueType = "Service Request with Approvals" // only display the sum on this issue type
def linkedIssueType = "Sub-task" // calculates for all linked issues of this type
def customField = "SLA NEW DUE DATE" // the custom field that you want to sum up
if (issue.getIssueType().name == issueType) {
def issueLinkManager = ComponentAccessor.getIssueLinkManager()
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def sum = 0
issueLinkManager.getOutwardLinks(issue.id).each {issueLink ->
def linkedIssue = issueLink.getDestinationObject()
if (linkedIssue.getIssueType().name == linkedIssueType) {
def technicalPointsField = customFieldManager.getCustomFieldObjectsByName(customField)[0]
sum += linkedIssue.getCustomFieldValue(technicalPointsField)?:0
}
}
return sum
}