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
Published Feb 07, 2019 in Marketplace Apps

A Timeless Love Story

It started as any story starts, on a normal, rainy day.   Admin meets App, and her name was Klok2, and like any first relationship we were both trying to make it work but neither one knew what...

466 views 8 27
Read article

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