# All Sub-tasks Resolved

**URL:** <https://forum.library.adaptavist.com/t/all-sub-tasks-resolved/352>\
**Category:** Scripts\
**Tags:** data-center, post-function\
**Created:** [July 28, 2023, 9:54am UTC](https://forum.library.adaptavist.com/t/all-sub-tasks-resolved/352 "2023-07-28T09:54:56Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Marcus](https://avatars.discourse-cdn.com/v4/letter/m/85e7bf/32.png) [@Marcus](https://forum.library.adaptavist.com/u/Marcus)\
**Post date:** [July 28, 2023, 9:54am UTC](https://forum.library.adaptavist.com/t/all-sub-tasks-resolved/352/1 "2023-07-28T09:54:57Z")

</div>

Hey I am simply trying to check if each sub-task is resolved. But it just keeps returning the keys of the sub-tasks.

I have the following, which is pretty much the same as [https://docs.adaptavist.com/sr4js/6.27.0/features/workflows/conditions/built-in-conditions/all-sub-tasks-resolved](https://docs.adaptavist.com/sr4js/6.27.0/features/workflows/conditions/built-in-conditions/all-sub-tasks-resolved)

```auto
import com.atlassian.jira.component.ComponentAccessor
def issueManager = ComponentAccessor.issueManager
def issueKey = 'TEST-1'
def issue = issueManager.getIssueObject(issueKey)
def subTasks = issue.getSubTaskObjects()

subTasks.each {
    if (!it.resolution) {
        return false
    }
}

```

This just returns [TEST-2, TEST-3] in the results, when it actually should be false.

What am I missing?

---

<div class="post-metadata">

**Author:** ![mclark](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.library.adaptavist.com/mclark/32/176_2.png) [@mclark](https://forum.library.adaptavist.com/u/mclark)\
**Post date:** [July 28, 2023, 10:46am UTC](https://forum.library.adaptavist.com/t/all-sub-tasks-resolved/352/2 "2023-07-28T10:46:40Z")

</div>

Hi Marcus

The [each](https://docs.groovy-lang.org/latest/html/groovy-jdk/java/util/List.html#each(groovy.lang.Closure)) closure is a groovy loop, similar to a java for loop.  
It does not return the result of what you do inside the loop. It returns the list itself.

If you want to return some result based on logic you do on each item in the closure, you probably want the [any](https://docs.groovy-lang.org/latest/html/groovy-jdk/java/lang/Iterable.html#any(groovy.lang.Closure)) closure

You should be able to do something like this:

```auto
Issues.getByKey('SSPA-1').subTaskObjects.any { !it.resolution }

```

Kind regards,  
Matthew

---

<div class="post-metadata">

**Author:** ![Marcus](https://avatars.discourse-cdn.com/v4/letter/m/85e7bf/32.png) [@Marcus](https://forum.library.adaptavist.com/u/Marcus)\
**Post date:** [July 28, 2023, 11:16am UTC](https://forum.library.adaptavist.com/t/all-sub-tasks-resolved/352/3 "2023-07-28T11:16:47Z")

</div>

Heya mclark, thanks for your quick reply.  
I thought I already tried this and was going crazy 🤡.

For anyone else struggling with this, I got it working with the following:

```auto
import com.atlassian.jira.component.ComponentAccessor
def issueManager = ComponentAccessor.issueManager
def issueKey = 'TEST-1'
def issue = issueManager.getIssueObject(issueKey)
def parentsubtasks = issue.parentObject.getSubTaskObjects()

parentsubtasks.every {it.getStatus().getName() == "Resolved"}

```

---

<div class="post-metadata">

**Author:** ![Marcus](https://avatars.discourse-cdn.com/v4/letter/m/85e7bf/32.png) [@Marcus](https://forum.library.adaptavist.com/u/Marcus)\
**Post date:** [July 28, 2023, 11:37am UTC](https://forum.library.adaptavist.com/t/all-sub-tasks-resolved/352/4 "2023-07-28T11:37:54Z")

</div>

@mclark ah I have another question.

I can’t seem to get this to work within my post-function.

The post-function fires when a sub-task transitions to resolved, it should then check that _every_ sub-task is resolved in the parent.

It seems like it counts the trigger sub-task as not resolved, and therefore returns false.

```auto
def parentsubtasks = issue.parentObject.getSubTaskObjects()

if (parentsubtasks.every {it.resolution}
    )

```

```auto
def parentsubtasks = issue.parentObject.getSubTaskObjects()

if (parentsubtasks.every {it.getStatus().getName() == "Resolved"}
    )

```

Both won’t work.

---

<div class="post-metadata">

**Author:** ![Marcus](https://avatars.discourse-cdn.com/v4/letter/m/85e7bf/32.png) [@Marcus](https://forum.library.adaptavist.com/u/Marcus)\
**Post date:** [July 28, 2023, 12:00pm UTC](https://forum.library.adaptavist.com/t/all-sub-tasks-resolved/352/5 "2023-07-28T12:00:32Z")

</div>

Nevermind, answered my own question! Haha.

Here’s my result, this checks if the sub-tasks are resolved and if the triggerissue contains _sometext_ in it’s summary:

```auto
import com.atlassian.jira.component.ComponentAccessor
def issueManager = ComponentAccessor.issueManager
def issueKey = 'TEST-1'
def issue = issueManager.getIssueObject(issueKey)
def parentsubtasks = issue.parentObject.getSubTaskObjects()
def verifyparentsubstaksstatus = true
def verifyparentsubstakssummary = true

parentsubtasks.every { subtask ->
    if (!issue.getStatus().getName() == "Resolved") {
        verifyparentsubstaksstatus = false
        return
    }
}

if (!issue.summary.contains("sometext")) {
        verifyparentsubstakssummary = false
        return 
    }

if (verifyparentsubstaksstatus && verifyparentsubstakssummary) {
    "Perfect!"
} else {
    "Something's not right"
}

```

---

<div class="post-metadata">

**Author:** ![mclark](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.library.adaptavist.com/mclark/32/176_2.png) [@mclark](https://forum.library.adaptavist.com/u/mclark)\
**Post date:** [July 28, 2023, 2:12pm UTC](https://forum.library.adaptavist.com/t/all-sub-tasks-resolved/352/6 "2023-07-28T14:12:12Z")

</div>

You are using the triggering `issue` variable which holds “TEST-1” inside the `every` closure instead of the `subtask` closure scoped variable, so I am not sure that it is working how you want it to.

Also, you set a variable outside the closure from inside `every` loop. You can use the return of `every` as the variable value.

Maybe you want something like this:

```auto
import com.atlassian.jira.component.ComponentAccessor

def issueManager = ComponentAccessor.issueManager
def issueKey = 'TEST-2'
def issue = issueManager.getIssueObject(issueKey)

if(!issue.isSubTask()) {
    // if the triggering issue is not a subtask do nothing
    return
}

// get all sibling subtasks
def siblingSubtasks = issue.parentObject.getSubTaskObjects()

def verifySiblingSubstaskStatuses = siblingSubtasks.every { subtask ->
    //return true if every sibling subtask is in the Resolved state else return false
    subtask.status.name == "Resolved"
}

// return true if the triggering sub-task issue contains the word "sometext"
def triggeringIssueSummaryCheck = issue.summary.contains("sometext")

if (triggeringIssueSummaryCheck && verifySiblingSubstaskStatuses) {
 return "Perfect!"
} else {
    "Something's not right"
}

```

Also, if checking the `issue.resolution` is not working, it might be because that status transition to the "Resolution` might not set the resolution field.

You can always raise a support case [here](https://productsupport.adaptavist.com/servicedesk/customer/portal/2) if it is still not right and we can work through it via support.

---

<div class="post-metadata">

**Author:** ![Marcus](https://avatars.discourse-cdn.com/v4/letter/m/85e7bf/32.png) [@Marcus](https://forum.library.adaptavist.com/u/Marcus)\
**Post date:** [August 3, 2023, 3:04pm UTC](https://forum.library.adaptavist.com/t/all-sub-tasks-resolved/352/7 "2023-08-03T15:04:38Z")

</div>

Yeah you’re right I got it properly working with your changes.

I also had to change siblingSubtasks to  
`def siblingSubtasks = issue.parentObject.getSubTaskObjects().findAll { it != issue }`

Since it shouldn’t include the triggering sub-task.

Thanks a lot mclark.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex019/uploads/adaptavistlibrary/original/1X/ceb18adf14fa58b4c6de03aa69ada8b07359620c.png) [@system](https://forum.library.adaptavist.com/u/system)\
**Post date:** [January 30, 2024, 3:05pm UTC](https://forum.library.adaptavist.com/t/all-sub-tasks-resolved/352/8 "2024-01-30T15:05:01Z")

</div>

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.
