Groovy Script for auto transition of Subtask which can be included in post function of parent ticket

Hi All,

If someone can help me out with a script for auto transition which can be used or included in the post function of parent ticket. So all I need to do is auto transition of Subtask with the transition of parent ticket.

Have just started working on JIRA and I am pretty much new to scripting  as well.

So any help on this would be great.

Thanks

Amir Vegdani

4 answers

1 accepted

2 votes
Mahesh S Community Champion Jun 07, 2016

Here, I have Sub-tasks under parent story. When the parent's transition is changed, the Sub-tasks will be moved to the Closed state. This script is placed in post function of Parent's workflow transition. Specify the ResolutionId and JIRA status Id in setResolutionId and setAction respectively

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();
   }
  }
 }
}

Please let me know your results. smile

What's your question? Does this relate to the original question? If not please create a new one.

Mahesh S Community Champion Jun 07, 2016

@Jamie Echlin [Adaptavist] Nope, this not a question. I saw this while randomly navigating here. So I thought of providing the solution to the above mentioned question, eventhough it is an old one. This is an answer!

oh ok cool, thanks!

0 vote

Is it on all actions or just one, or particular actions?

Hi Jamie, I need to do this on a particular transition only. For e.g. we raise issue on JIRA, once we get projects. These projects might start on a future date. So on that particular date when I move my parent ticket to In Progress from Awaiting Project Start, I want all the sub task to move into In Progress from Awaiting Project Start.

I too need this to be implemented in the post function of a parent issue transition. Requirement: clicking on the "start progress" button in the parent task should automatically set the status of all underlying sub tasks to "In Progress".

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
Bridget Sauer
Published Thursday in Marketplace Apps

Calling all developers––You're invited to Atlas Camp 2018

 Atlas Camp   is our developer event which will take place in Barcelona, Spain  from the 6th -7th of   September . This is a great opportunity to meet other developers and get n...

128 views 0 5
Read article

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