In this exercise we want to create a new custom field of type Scriptfield of Scriptrunner Jira plugin. This script field will sum all the values of some customfield of its subtasks.

Just go to Add-ons –> Scriptrunner –> Script Fields and create a new Script field like this (Total…):

Captura de pantalla 2019-08-02 a las 19.31.55

Now place a script like this:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.fields.CustomField

//return number subtasks
issue.getSubTaskObjects().size()

CustomField total = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Total")
double totalSum = 0;
for(Issue subtask: issue.getSubTaskObjects()){
    if(subtask.getCustomFieldValue(total) != null)
        totalSum += subtask.getCustomFieldValue(total)
}

return totalSum

Remember to change “Total” by the name of the customfield to sum. Post by MrAddon

Posted by:.

One thought on “How to create a Jira Server script field to show in all parent ticket the SUM of some customfield of all subtasks

  1. Can you please update the script, scrip runner updated it classes and deprecated few.
    What if when an issuetype is created as a subtask type, will the script work as expected.

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s