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

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
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Bridget Sauer
Published Thursday in Marketplace Apps

Calling all developers––You're invited to Atlas Camp 2018

 Atlas Camp   is our developer event which will take place in Barcelona, Spain  from the 6th -7th of   September . This is a great opportunity to meet other developers and get n...

282 views 0 6
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