Calculate the sum of all values of a Custom Field in linked issues

Add together multiple custom field values from linked issues and display the total in a ScriptRunner Scripted field.

  • Template: Number Field
  • Search Template: Number Searcher


Jira Jira (7.7 - 8.6)

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 String issueTypeName = "Bug" // the linked issues with that issue type will used final String linkedIssueType = "Support" // the values of that custom field - of type number - we want to sum up final String customFieldName = "Number of Users" if ( != issueTypeName) { return null } def linkedIssues = ComponentAccessor.issueLinkManager.getOutwardLinks( { == linkedIssueType } if (!linkedIssues) { return null } def customField = ComponentAccessor.customFieldManager.getCustomFieldObjects(linkedIssues.first().destinationObject).findByName(customFieldName) if (!customField) { log.debug "Custom field is not configured for that context" return null } linkedIssues*.destinationObject.sum { Issue it -> it.getCustomFieldValue(customField) ?: 0 }
Discovered an issue? Report it here

Suggested for you

Appears in these Collections