Hello Atlassian community! I'm trying to create a Scripted Field that will sum up the value of a number field on all linked issues, however so far I can only get it to work in one direction or the other. I've found some threads about including both Inward and Outward links in other contexts, but I can't get them to work for a Scripted Field.
Has anyone set something like this up before, or have any insight? Here's the two versions of the scripts that work, one for each direction:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
def linkedIssues = ComponentAccessor.issueLinkManager.getInwardLinks(issue.id)
if (!linkedIssues) {
return null
}
def customField = ComponentAccessor.customFieldManager.getCustomFieldObjects(linkedIssues.first().sourceObject).findByName('Number Custom Field')
if (!customField) {
log.debug "Custom field is not configured for that context"
return null
}
linkedIssues*.sourceObject.sum { Issue it -> it.getCustomFieldValue(customField) ?: 0 }
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
def linkedIssues = ComponentAccessor.issueLinkManager.getOutwardLinks(issue.id)
if (!linkedIssues) {
return null
}
def customField = ComponentAccessor.customFieldManager.getCustomFieldObjects(linkedIssues.first().destinationObject).findByName('Number Custom Field')
if (!customField) {
log.debug "Custom field is not configured for that context"
return null
}
linkedIssues*.destinationObject.sum { Issue it -> it.getCustomFieldValue(customField) ?: 0 }