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
4,293,676
Community Members
 
Community Events
165
Community Groups

Count Number of Subtasks and put on parent's custom field

 

I'm currently working on burnup chart to see the count of subtasks of each story.

So, I'm thinking about automate the count of subtasks each time a subtasks created, then put it on Custom Field of the parent, let's say `Number of Tasks`.

I've been looking and didn't found any beginner advise how to do this. Any help will be appreciated 

2 answers

1 accepted

Something like this should work in a number Script Field to count the number of subtasks for each issue. 

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
}

 Regards,

Josh

Works great, thanks Josh

Joshua Yamdogo @ Adaptavist This is great! 

Is it possible to filter this to only count specifically depending on subtask issue type?

Like Benjamin Dorsey likes this

How can we modify to count only sub-tasks of certain status? 

I'm getting this error message when I try this snippet:

Error

An error occurred whilst running the scripted field.

org.codehaus.groovy.runtime.InvokerInvocationException: groovy.lang.MissingMethodException: No signature of method: java.util.LinkedHashMap.getIssueType() is applicable for argument types: () values: [] at TestScriptedFieldExecution1_groovyProxy.run(Unknown Source) Caused by: groovy.lang.MissingMethodException: No signature of method: java.util.LinkedHashMap.getIssueType() is applicable for argument types: () values: [] at Script1.run(Script1.groovy:1) at Script1$run.call(Unknown Source) at com.adaptavist.sr.cloud.workflow.AbstractScript.evaluate(AbstractScript.groovy:39) at com.adaptavist.sr.cloud.events.ScriptedFieldExecution.run(ScriptedFieldExecution.groovy:30) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at TestScriptedFieldExecution1_groovyProxy.run(Unknown Source) at com.adaptavist.sr.cloud.MainHandler.executeScript(MainHandler.groovy:402) at com.adaptavist.sr.cloud.MainHandler.processInput(MainHandler.groovy:347) at com.adaptavist.sr.cloud.MainHandler.access$0(MainHandler.groovy) at com.adaptavist.sr.cloud.MainHandler$_handleRequest_closure1.doCall(MainHandler.groovy:167) at com.adaptavist.sr.cloud.MainHandler$_handleRequest_closure1.call(MainHandler.groovy)

Hi Joshua Yamdogo @ Adaptavist ,

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

Your code is working as expected, but its displaying all tickets, but i don't want closed/done tickets display on the main ticket. Could you please suggest ?

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
}

 

Hi, 

You have to use the Scriptrunner plugin to create a plugin which runs on issue created event.

The script should be able to fetch the links using the issueLinkManager. The getOutwardLinks() method will fetch you all the child links for that specific issue.

-Praveen

Hi Praveen,

Thanks for the reply. And yes, I do eventually use Script Runner. What I've been doing is creating new custom field that automatically fetch the child / subtasks of current issue and you can further filter is for resolved only.

But I didn't use the issueLinkManager, can you give me some example so that this might be one of the alternative, hopefully more efficient, answer

Hi, 

I hope you are using the post function script for this. Please check this for some example.

-Praveen

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Apps & Integrations

Marketplace Partner Spotlight: AppLiger

This month the spotlight is on AppLiger. We caught up with Pavel Pavlovsky, CEO and Product Manager, to learn how the company started and what fuels the team's creativity.    Atlassian:...

331 views 0 7
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