Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

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

Amir Vegdani January 11, 2015

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
Answer accepted
Mahesh S
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 7, 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

JamieA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 7, 2016

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

Mahesh S
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 7, 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!

JamieA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 8, 2016

oh ok cool, thanks!

0 votes
Shreeshail
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
March 3, 2015

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".

0 votes
Amir Vegdani January 13, 2015

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.

0 votes
JamieA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 13, 2015

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

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events