import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
// The issue type for which we want the scripted field to be displayed
final issueTypeName = 'Story'
// The values of that custom field - of type number - we want to sum up
final numberOfUsersFieldName = 'Story Points'
if (issue.issueType.name != issueTypeName) {
return null
}
def linkedIssues = ComponentAccessor.issueLinkManager.getOutwardLinks(issue.id).findAll { it.destinationObject.issueType.name }
if (!linkedIssues) {
return null
}
def numberOfUsersField = ComponentAccessor.customFieldManager.getCustomFieldObjects(linkedIssues.first().destinationObject).findByName(numberOfUsersFieldName)
if (!numberOfUsersField) {
log.debug "Custom field is not configured for that context"
return null
}
linkedIssues*.destinationObject.sum { Issue it -> it.getCustomFieldValue(numberOfUsersField) ?: 0 }