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:.

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 )

Google photo

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

Twitter picture

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

Facebook photo

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

Connecting to %s