get parent subtasks and return true if all subtasks have a status

I'm trying to make a script that gets the parent subtasks list and check if all the subtasks have the status as 'Resolved' and if so it returns true.
I’m trying to implement this at the post function Conditional execution:  Only if condition is true

I’ve just started to work with groovy so i'm little clueless

that's what I’ve came up with but it doesn't work

import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.comments.CommentManager
import com.opensymphony.workflow.WorkflowContext
import org.apache.log4j.Category
import com.atlassian.jira.config.SubTaskManager
import com.atlassian.jira.workflow.WorkflowTransitionUtil;
import com.atlassian.jira.workflow.WorkflowTransitionUtilImpl;
import com.atlassian.jira.util.JiraUtils;

boolean canResolve = true;
Collection subTasks = issue.getParentObject().getSubTaskObjects();

for(subtask in subTasks) {
        String status = subtask.getStatusObject().getSimpleStatus().getName();
        if(status != "RESOLVED") //also tried with "Resolved"

          canResolve = false;

        }

return canResolve;

EDIT: the purpose is to transition the parent issue to resolved only when all subtasks are resolved

1 answer

0 vote
Joe Pitt Community Champion Sep 24, 2015

What is the purpose? You can restrict a transition to only be available if all subtasks are resolved by using the sub-task blocking condition. See https://confluence.atlassian.com/jira/configuring-sub-tasks-185729507.html

Suggest an answer

Log in or Sign up to answer
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Julia Dillon
Posted Apr 17, 2018 in Jira

Tell us how your team runs on Jira!

Hey Atlassian Community! Today we are launching a bunch of customer stories about the amazing work teams, like Dropbox and Twilio, are doing with Jira. You can check out the stories here. The thi...

763 views 2 19
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you