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

Riadhi_Aditya_Hermawan May 7, 2018

 

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

0 votes
Answer accepted
Joshua Yamdogo @ Adaptavist
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 8, 2018

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

Riadhi_Aditya_Hermawan May 8, 2018

Works great, thanks Josh

Joe Charman
Contributor
June 4, 2019

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
Sarath September 18, 2020

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

Oros, Jesus
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
November 4, 2020

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)

Lakshmi S
Contributor
October 1, 2021

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
}

 

0 votes
Praveen
Contributor
May 8, 2018

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

Riadhi_Aditya_Hermawan May 8, 2018

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

Praveen
Contributor
May 8, 2018

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
AUG Leaders

Atlassian Community Events