Skip to content

Instantly share code, notes, and snippets.

Created August 2, 2017 07:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/60c80f93577b7d2b3e50fea932c6b68a to your computer and use it in GitHub Desktop.
Save anonymous/60c80f93577b7d2b3e50fea932c6b68a to your computer and use it in GitHub Desktop.
Auto update subtask status when transition on parent
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.resolution.Resolution
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.IssueInputParameters
log = Category.getInstance("com.onresolve.jira.groovy.AutoCloseChildIssues")
String currentUser = ((WorkflowContext) transientVars.get("context")).getCaller();
WorkflowTransitionUtil workflowTransitionUtil = ( WorkflowTransitionUtil ) JiraUtils.loadComponent( WorkflowTransitionUtilImpl.class );
SubTaskManager subTaskManager = ComponentManager.getInstance().getSubTaskManager();
Collection subTasks = issue.getSubTaskObjects()
if (subTaskManager.subTasksEnabled && !subTasks.empty)
{
subTasks.each
{
if(it.issueTypeObject.name == "Sub-task")
{
String status = it.getStatus().get("name").toString()
if(!(status.equals("Closed")))
{
it.setResolutionId("7")
log.debug ("issue.statusObject.name: " + issue.statusObject.name)
workflowTransitionUtil.setIssue(it);
workflowTransitionUtil.setUsername(currentUser);
workflowTransitionUtil.setAction(161)
CommentManager commentManager = (CommentManager) ComponentManager.getComponentInstanceOfType(CommentManager.class);
String comment = "Moving to *new status* status as a result of the *this transition* action being applied to the parent.";
commentManager.create(it, currentUser, comment, true);
workflowTransitionUtil.validate();
workflowTransitionUtil.progress();
}
}
}
}
@tarunsapra
Copy link

tarunsapra commented Aug 2, 2017

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.resolution.Resolution
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.IssueInputParameters
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.Issue;


def Category log = Category.getInstance("com.onresolve.jira.groovy.AutoCloseChildIssues")
String currentUser = ((WorkflowContext) transientVars.get("context")).getCaller();
WorkflowTransitionUtil workflowTransitionUtil = ( WorkflowTransitionUtil ) JiraUtils.loadComponent( WorkflowTransitionUtilImpl.class );
SubTaskManager subTaskManager = ComponentAccessor.getSubTaskManager();
List<Issue> subTasks = issue.getSubTaskObjects()

if (subTaskManager.subTasksEnabled && !subTasks.empty) 
  {
   MutableIssue it = (MutableIssue)subTasks.first()   
   
      if(it.issueTypeObject.name == "Sub-task")
      {
        if(!(status.equals("Closed")))
        {
          it.setResolutionId("7")
          log.debug ("issue.statusObject.name: " + issue.statusObject.name)
          workflowTransitionUtil.setIssue(it);
          workflowTransitionUtil.setUsername(currentUser);
          workflowTransitionUtil.setAction(161)
          CommentManager commentManager = (CommentManager) ComponentManager.getComponentInstanceOfType(CommentManager.class);
          String comment = "Moving to *new status* status as a result of the *this transition* action being applied to the parent.";
          commentManager.create(it, currentUser, comment, true);
          workflowTransitionUtil.validate();
          workflowTransitionUtil.progress();
        }
     }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment