Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Need to sum values in subtask custom field

David
Contributor
October 20, 2017

We are investigating ScriptRunner for JIRA.  We have a custom Number field used in subtasks and we wish to somehow calculate sums on the subtasks and group the sums by Task.  Is that possible?  thanks!

1 answer

0 votes
Joshua Yamdogo @ Adaptavist
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 14, 2017

Hi David, 

Are you still needing help with this? What you could is is create a Scripted Field that displays on all issues of type "Task". The scripted field would search all sub-task issues, get values that they have in their custom fields, and return the sum of all of the values. Something like this:

import com.atlassian.jira.component.ComponentAccessor

if (issue.getIssueType().name == "Task") { // only calculate this for Task Issue Types
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def pointSum = 0
issue.getSubTaskObjects().each { subTask -> // go through all sub-tasks off the task
def pointsField = customFieldManager.getCustomFieldObjectByName("Your custom field") // name of the custom field to sum
pointSum += subTask.getCustomFieldValue(pointsField) ?: 0 // get value from each sub-task field
}
return pointSum
}

Sylvain Leduc
Contributor
April 23, 2019

Hi,

thanks for this, i was looking for the same kind of script :)

Except that i would need the average sum, something like "return total.pointSum / occurrences.pointSum" if you know what i mean ?

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events