Hello Community,
I want to create a ScriptedField that sums up the number values of a custom field of all linked issues. Therefore I use this code: https://library.adaptavist.com/entity/calculate-the-sum-of-all-values-of-a-custom-field-in-linked-issues.
In applied the code to my project but I receive an error message: cannot return value of type java.lang.Object on method returning type java.lang.Double
The error message arises in the last line of the code ( linkedIssues*....)
Can you help me with this?
Best thanks in advance!
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 = 'SUD Lehrkraft Semester'
// The linked issues with that issue type will used
final linkedIssueType = 'Related'
// The values of that custom field - of type number - we want to sum up
final numberOfUsersFieldName = 'Modul SWS'
if (issue.issueType.name != issueTypeName) {
return null
log.info("IssueTypes do not match")
}
def linkedIssues = ComponentAccessor.issueLinkManager.getOutwardLinks(issue.id).findAll { it.destinationObject.issueType.name == linkedIssueType }
if (!linkedIssues) {
return null
log.info("No linked Issues found")
}
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 }