Forums

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

Get a list of subtasks and check status of each subtask

Vithya Vasanthan
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!
April 25, 2020

I'm trying to write a condition where all subtasks in an issue needs to be in done or canceled state, only then clone the issue. However, the for loop is not checking each element of the collection just the first one. I tried quite a few variations of the for loops yet the result is the same. 

The condition should fail if there are any other status for the same issue type.

This is the script:

Collection subTasks = issue.getParentObject().getSubTaskObjects()

for(subTask in subTasks)

{ if (issue.issueType.name == "<issue type name>" && (issue.status?.name == 'Done' || issue.status?.name == 'Canceled')){

return true

} }

 

 

 

1 answer

1 accepted

3 votes
Answer accepted
Oliver Siebenmarck _Polymetis Apps_
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.
April 27, 2020

Hi Vithya,

I am by no means an expert in either Groovy or ScriptRunner, but from what I can tell, your script gets all sub tasks and checks whether each one of the satisfies your condition, i.e. the if-part. As soon as one sub tasks does, it return true.

Basically it checks if at least one of the sub tasks is of type '<issue type name>' and is either Done or Canceled.

You, however want to make sure that all sub tasks satisfy that condition. You can also formulate that as: If there is at least one sub task that does not satisfy my condition, fail the condition. Now, we can simply reverse your script:

Collection subTasks = issue.getParentObject().getSubTaskObjects()

for(subTask in subTasks) {
if !(issue.issueType.name == "<issue type name>" &&
(issue.status?.name == 'Done' || issue.status?.name == 'Canceled')) {
return false }
}

// After the loop is done, if the script has not yet return false,
// we can return true

return true

Hope that helps!

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
SERVER
VERSION
8.3.2
TAGS
AUG Leaders

Atlassian Community Events