Forums

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

Counting unresolved subtasks

Jamie Rogers
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.
January 28, 2019

Hi

I am trying to create script field that shows a count of the unresolved sub-tasks on an issue. 

I can count all of them using the solution found here - but have been unable to work out how to put in the condition to only return unresolved sub-tasks.

I have also tried modifying the issuetype property in this solution (for counting linked issues) but this does not work for me either. I guess thats not the correct way or I'm missing something.

Scriptrunner is sill new to me so would appreciate any assistance anyone can offer.

Regards, Jamie 

1 answer

1 accepted

0 votes
Answer accepted
Nir Haimov
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 28, 2019

Hi,

Try this in your scriptedfied:

def subTaskSum = 0
issue.getSubTaskObjects()?.each {
subtask -> subtask.getResolutionObject()!=null?subTaskSum += 1:subTaskSum
}

I didn't try it, but it should work.

Let me know if it did or not.

Jamie Rogers
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.
January 29, 2019

Hi @Nir Haimov

Thanks for the reply.

Unfortunately this did not work as the script field box complains this is incorrect "subtask.getResolutionObject()" and to use "issue.getResolution()" instead - which also doesn't work.

I am running Jira 7.13 and Scriptrunner 5.4.43.

Regards, Jamie

Nir Haimov
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 30, 2019

Hi @Jamie Rogers

Both "subtask.getResolutionObject()" and "issue.getResolution()" will work.

The error you get is just a suggestion, it's a warning.

Any way, i tested and it works, all you need is just to add in the end of the script this line:

return subTaskSum

So your final code is:

def subTaskSum = 0
issue.getSubTaskObjects()?.each {
    subtask -> subtask.getResolution()!=null?subTaskSum += 1:subTaskSum
}
return subTaskSum

Tested in Jira 7.12.2 and Scriptrunner 5.4.40

Like Lakshmi likes this
Jamie Rogers
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.
January 30, 2019

Hi @Nir Haimov

This works, thank you.

I modified the != to == to get the value I was after was I wanted unresolved subtasks but good to know I can also use != if the requirements change.

Regards, Jamie 

Like Lakshmi likes this
Lakshmi
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.
October 4, 2021

Thank you for your script. Its helped me in my requirement.

The requirement is, 

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

 

def subTaskSum = 0
issue.getSubTaskObjects()?.each {
subtask -> subtask.getResolution()==null?subTaskSum += 1:subTaskSum
}
return subTaskSum

Suggest an answer

Log in or Sign up to answer