Forums

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

Count the subtasks of the main ticket of one type and add the count to a scripted field

Lakshmi CH
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.
August 12, 2024

Hi Team,

 I have a requirement to count the no.of "Connection" subtasks and display them on the custom field. We have two subtask, one is a "Sub-task" and another is "Connection". The main parent ticket will have both Sub-task and Connection subtasks, but want to display the only "Connection" tickets, the following scripts is displaying all subtasks. is there any correction to update the only "Connection" subtasks in that custom field "Connection Count" ?

Scripted Field : Connection Count

 

 

def subTaskSum = 0

issue.getSubTaskObjects()?.each {

    subtask -> subtask.getResolution()==null?subTaskSum += 1:subTaskSum

}

return subTaskSum

1 answer

1 accepted

0 votes
Answer accepted
Tessa Tuteleers
Community Champion
August 12, 2024

Hi @Lakshmi CH , 

Do I understand that you want to have a counter on an issue that counts all: 

- subtasks, but only of specific type "Connection"

- No further conditions? 

I ask this because in your script you have put a condition on the resolution of the subtasks, which does not reflect in your requirements. 

You were already going in the correct direction with your code, I just altered it a bit to reflect issuetype instead of resolution. 

 

def numberofConnectionSubtasks = issue.getSubTaskObjects().findAll() { a ->
a.getIssueType().name == "Connection"
}.size()

return numberofConnectionSubtasks ? numberofConnectionSubtasks as Integer : null


instead of the name, you could better use the id of the issuetype, as this is more stable. ;) 

 

Hope this helps, 

Tessa

Lakshmi CH
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.
August 13, 2024

Thank you so much @Tessa Tuteleers for your quick response. Its working as expected. 

Like Tessa Tuteleers likes this

Suggest an answer

Log in or Sign up to answer