Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

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, 

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 Marketplace Apps & Integrations

🤺 Atlympic Event: Partnerships

Hello Community!  Quick disclaimer: We are running a contest on Community (The Atlympics!) from July 23rd - August 8th of 2021. If you are interested in participating in this contest (prizes! ...

199 views 3 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