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…):
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
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.
LikeLike