Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

How to get the number of non closed subtasks

Connor Jakes May 17, 2018

I'm looking to make a custom field with script runner to count the number of sub tasks that aren't closed. 

I've been able to find a simple way of getting the number of sub tasks, but havn't been able to find a good library of functions that are available in the inline script editor.

issue.getSubTaskObjects().size()

 

obviously the simple solution would be to get the total count, then loop through the subtasks, subtracting from the original count for every one found to be in the closed state. I don't know if theres a simple one line solution though, such as issue.getSubTaskObjectsInStatus("closed").size() or something though. Can anyone help point me to a good library of available functions, or offer a quick solution?

2 answers

1 accepted

0 votes
Answer accepted
Connor Jakes May 17, 2018

This is what I've come up with so far

def subtasks = 0
for (i in issue.getSubTaskObjects()){
if (i.getStatus().getName() != "Closed")
subtasks += 1
}

return subtasks

 

0 votes
Fabio Racobaldo _Catworkx_
Community Champion
May 17, 2018

Hi Connor, 

 

here your code :

import java.util.Collection;
import com.atlassian.jira.issue.Issue;

Issue issue = issue;
Collection<Issue> subTasks = issue.getSubTaskObjects();
int count = 0;
for(Issue is : subTasks){
if(!is.getStatus().getName().equalsIgnoreCase("YOUR_STATUS_NAME_HERE"))
count++;
}
return count;

Hope this helps,

Ciao,

Fabio 

Suggest an answer

Log in or Sign up to answer