Need to sum values in subtask custom field

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

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
}

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted Oct 11, 2018 in Marketplace Apps

You + one app + a desert island...

Hi all! My name is Miles and I work on the Marketplace team. We’re looking for better ways to recommend and suggest apps that are truly crowd favorites, so of course we wanted to poll the Community. ...

3,372 views 6 6
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you