Auto Transition a Parent Task in JIRA Only When All Subtasks Are in Certain States

Guest post from Peter Van de Voorde. Learn how to automatically transition a parent task in JIRA only when all subtasks are in certain states.

Auto Transition

In this post I’ll explain how you can automatically transition a Parent Issue when all subtasks are in certain states

We’ll create a custom post function using the Script Runner plugin

I’ll explain the process in a few simple steps:

  1. Install the Script  Runner plugin using your JIRA Add-ons menu.
  2. Create a Draft of the workflow your subtask is using.
  3. Open the transition on which you want trigger the transition of the Parent.
  4. Go to the Post Function Tab and click on add a post function
  5. Select Script Post-Function
  6. Select Custom script post-function
  7. Now paste in the following code and fill in the number of the transition you want to Parent to execute and change the list of states your subtasks should be in to allow the Parent to transition:

import com.atlassian.jira.ComponentManager;
importcom.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;
import com.atlassian.jira.issue.MutableIssue;

log =Category.getInstance(“com.onresolve.jira.groovy.AutoCloseChildIssues”);String currentUser =((WorkflowContext) transientVars.get(“context”)).getCaller();WorkflowTransitionUtil workflowTransitionUtil =(WorkflowTransitionUtil)JiraUtils.loadComponent(WorkflowTransitionUtilImpl.class);MutableIssue parent = issue.getParentObject();SubTaskManager subTaskManager =ComponentManager.getInstance().getSubTaskManager();Collection subTasks = parent.getSubTaskObjects();if(subTaskManager.subTasksEnabled){boolean transitionParent =true;for(subtask in subTasks){String status = subtask.getStatusObject().getSimpleStatus().getName();if(status !=”Resolved”&& status !=”Testing”&& status !=”Waiting For Approval”&& status !=”Closed”&& status !=”Approved”){
transitionParent =false;}}if(transitionParent){
workflowTransitionUtil.setIssue(parent);
workflowTransitionUtil.setUserkey(currentUser);
workflowTransitionUtil.setAction(5);
workflowTransitionUtil.validate();
workflowTransitionUtil.progress();}}

  1. Press Add.
  2. Move your new Post Function to the bottom of the post function list (behind the Re-index post function).
  3. Done.

About Peter Van de Voorde

Peter is a 30-something Belgian with a passion about everything Agile. By day he’s an Atlassian Expert and ALM Consultant at RealDolmen. In the evening he’s a family man, an active member of Atlassian Answers and the Atlassian Belgian User Group, and a boardgame fanatic. For more by Peter, visit his website: http://www.petervandevoorde.com/

Atlasssian expert resources

Visit our blog for expert news and articles from the Atlassian world. On our resources page you will find recorded webinars, white papers, podcasts, videos and more.

The Software Blog

Read our blog for articles offering best practice advice written by Atlassian experts, as well as the latest news concerning your software.

Software White Papers and Guides

Dive deep into Atlassian software with our white papers and guides on individual tools, partner products, services, and best practices, written by the experts.

Expert Webinars

All of our webinars are pre-recorded and available to watch on-demand. Enjoy everything from partner features to application demos and updates from Atlassian experts.

Subscribe to our Newsletter

Subscribe to our Newsletter