Count Number of Subtasks and add on parent's custom scripted field

Lakshmi S October 1, 2021

Hi Team,

 I have a requirement "Add Sub-Task Count (Numeric) field to be auto-updated based on related sub-tasks (child) with a Status != Closed. "

I have tried with below code as per our old community tickets. Its working , but i would like to get only open tickets count, not all tickets count. Any suggestion how to add the jql in this script?

 

if (issue.getIssueType().name != "Sub-task") { // only calculate this for non-subtask issues
def subTaskSum = 0
issue.getSubTaskObjects()?.each { subtask -> // go through all subTask issues
subTaskSum += 1
}
return subTaskSum

 

3 answers

1 accepted

0 votes
Answer accepted
Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
October 1, 2021

You'll need to wrap the subTaskSum += 1 in an "if subtask.getResolution()" statement, so that it only counts for unresolved issues.

Lakshmi S October 4, 2021

Thank you @Nic Brough -Adaptavist-  and Atlassian Community members. You are always very fast in responses and helping to Atlassian administrators. Thanks much.

This is code is working as espected.

def subTaskSum = 0
issue.getSubTaskObjects()?.each {
subtask -> subtask.getResolution()==null?subTaskSum += 1:subTaskSum
}
return subTaskSum 

0 votes
Guaraci Nakamura April 8, 2022

I would like to have a field which shows the substasks bar progress as a percentage number.

I am also wondering to have custom fields which counts the number of each substasks category status (issue atribute).

- Pending

- In progress

- Concluded

0 votes
Guaraci Nakamura April 8, 2022

Where do i include this code on jira?

Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
April 9, 2022

In a scriptrunner script.  The code given will work for a scripted field, post-function or listener, with a couple of other lines appropriate to where it is being run.

You could use something similar to look at all the sub-tasks of an issue and extract field data from them - the code Lakshmi gave us is iterating over the sub-tasks and adding 1 to a variable for each resolution found, but you could read any field and perform any logic you wanted to in there.

Manny May 2, 2022

Can we get percentage of story points done under an epic using script runner? 

Suggest an answer

Log in or Sign up to answer