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

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.

Share
Share
Share
Share

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

This is related to my previous blog post here .

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;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;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();}}
  8. Press Add.
  9. Move your new Post Function to the bottom of the post function list (behind the Re-index post function).
  10. 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. To see Peter’s previous guest posts for Clearvision, see our guest posts tag. For more by Peter, visit his website: http://www.petervandevoorde.com/

Share
Share
Share
Share

Reader Interactions

Related blog articles

    Reader Interactions