Jira: how to set in progress status when a subtask move to in progress using Script Runner

This is something that Jira would have done by default but it doesn’t…
So If you require that the parent issue change status from TO DO to In Progress when a subtask move from TO DO to In progress, this is the solution.
Buy Script Runner that is cheap and allows you to do whatever you want.
Add a post function (script runner) to the transition of the subtask workflow.
Here is the code to add in the subtask transition post function from TO DO to In Progress

import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.ComponentManager
import com.atlassian.crowd.embedded.api.User
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.type.EventDispatchOption

import com.atlassian.jira.util.JiraUtils;
import com.atlassian.jira.workflow.WorkflowTransitionUtil;
import com.atlassian.jira.workflow.WorkflowTransitionUtilImpl;

def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
 
if (issue.isSubTask()) 
{
    def parentIssue = (MutableIssue)issue.getParentObject()
    def currentParentStatus = parentIssue.getStatusId()
    // if the parent has the id of the status TODO (change it with your Jira ID)
    if (currentParentStatus == "10000") 
    {
        WorkflowTransitionUtil workflowTransitionUtil = (WorkflowTransitionUtil) JiraUtils.loadComponent(WorkflowTransitionUtilImpl.class);
    	
    	workflowTransitionUtil.setIssue(parentIssue);
        // 61  is the Id of the transition from TO DO to In Progress
        workflowTransitionUtil.setAction(61);          
        workflowTransitionUtil.validate();
        workflowTransitionUtil.progress();
    }        
}

In order to manage it correctly I suggest adding also the change status from In Progress to TO DO when all subtask moved back to TO DO status.
To achieve this goal add the post function to the subtask transition from In Progress –> TO DO

import java.util.Collection;
import com.atlassian.jira.ComponentManager;
import com.atlassian.jira.config.SubTaskManager;
import com.atlassian.jira.event.issue.AbstractIssueEventListener;
import com.atlassian.jira.event.issue.IssueEvent;
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.issue.MutableIssue;
import com.atlassian.jira.issue.issuetype.IssueType;
import com.atlassian.jira.util.JiraUtils;
import com.atlassian.jira.workflow.WorkflowTransitionUtil;
import com.atlassian.jira.workflow.WorkflowTransitionUtilImpl;

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.type.EventDispatchOption

 
if (issue.isSubTask()) 
{
    def parentIssue = (MutableIssue)issue.getParentObject()
    def currentParentStatus = parentIssue.getStatusId()
    // if the parent is in status in progress
    if (currentParentStatus == "3") 
    {
        def areAllToDo = true;
        def subTaskIssues = (Collection<MutableIssue>) parentIssue.getSubTaskObjects();
        
        // I'll check all subtask's status
        for (MutableIssue subTask : subTaskIssues)
        {
            def subTaskStatusId = subTask.getStatusId();
            
            // even though this is a post function when you check the item's status that triggers this function it's the old one, so it's not updated
            // I'll check that all issues are in TO DO a part from this issue that will'be in In Progress
            if (subTaskStatusId != "10000" && issue.getId() != subTask.getId())
            {   
                areAllToDo = false;
                break;
            }
        }
        
        if (areAllToDo) {
            
            WorkflowTransitionUtil workflowTransitionUtil = (WorkflowTransitionUtil) 
            JiraUtils.loadComponent(WorkflowTransitionUtilImpl.class);

            workflowTransitionUtil.setIssue(parentIssue);
            // 111 is the transition Id from In progress to TO DO (Stop Progress)
            workflowTransitionUtil.setAction(111);              
            workflowTransitionUtil.validate();
            workflowTransitionUtil.progress();
        }
        
    }        
}
Annunci

Informazioni su Andrea Regoli

Project Manager .Net Developer WPF WP7 Asp.Net c# javascript ajax SQL sharepoint
Questa voce è stata pubblicata in Agile, Jira e contrassegnata con , , , . Contrassegna il permalink.

Rispondi

Inserisci i tuoi dati qui sotto o clicca su un'icona per effettuare l'accesso:

Logo WordPress.com

Stai commentando usando il tuo account WordPress.com. Chiudi sessione / Modifica )

Foto Twitter

Stai commentando usando il tuo account Twitter. Chiudi sessione / Modifica )

Foto di Facebook

Stai commentando usando il tuo account Facebook. Chiudi sessione / Modifica )

Google+ photo

Stai commentando usando il tuo account Google+. Chiudi sessione / Modifica )

Connessione a %s...