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!
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
}
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 ?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.