Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
Community Members
Community Events
Community Groups

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

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

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

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 

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

Where do i include this code on jira?

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.

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

Suggest an answer

Log in or Sign up to answer
Community showcase
Published in Jira Software

Upcoming changes to epic fields in company-managed projects

👋 Hi there Jira Community! A few months ago we shared with you plans around renaming epics in your company-managed projects. As part of these changes, we highlighted upcoming changes to epics on...

14,817 views 37 48
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you