Using Post function script to Transition Sub-Tasks

Hi All, I am new to groovy so need some advice on the post function scripts.

I would like to use a post script to transition all Sub-taks of the parent.

I found this script to close sub-tasks

https://jamieechlin.atlassian.net/wiki/display/GRV/Post+Functions#PostFunctions-Autocloseallsub-tasks

The question is, apart from the action ID, what else do I need to change to make it specific to my JIRA project?

specifically,

String currentUser = ((WorkflowContext) transientVars.get("context"))

Do I need to change "Context" to something more specific

workflowTransitionUtil.setIssue(it);

Do I need to change "it" to the issuetype of the subtask?

Also, Do I need to call a package (e.g. package com.onresolve.jira.groovy.canned.CannedScript) before running the script?

I am using the Post Function "Script Post-Function" -> Script file, using the absoulte file path.

I'm running JIRA v5.2.4 with Script Runner 2.1.12

This is what I have in the file, but at the moment it is not working....

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;

log = Category.getInstance("com.onresolve.jira.groovy.AutoTransitionChildIssues")

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 {
log.debug ("issue.statusObject.name: " + issue.statusObject.name)
workflowTransitionUtil.setIssue(it);
workflowTransitionUtil.setUsername(currentUser);
workflowTransitionUtil.setAction (101) // Transition ID e.g. 5 == RESOLVE ISSUE

// Add a comment so people have a clue why the child has been closed
CommentManager commentManager = (CommentManager) ComponentManager.getComponentInstanceOfType(CommentManager.class);
String comment = "*Assign Resolution* set as a result of the *Assign to Me* action being applied to the parent.";
commentManager.create(it, currentUser, comment, true);

// validate and transition issue
workflowTransitionUtil.validate();
workflowTransitionUtil.progress();
}

Any help would be appreciated.

Thanks

Paul

1 answer

1 accepted

This widget could not be displayed.
Henning Tietgens Community Champion Mar 03, 2014

See my answer here.

Thanks Henning. This works a treat.

Suggest an answer

Log in or Sign up to answer
Atlassian Summit 2018

Meet the community IRL

Atlassian Summit is an excellent opportunity for in-person support, training, and networking.

Learn more
Community showcase
Posted Aug 06, 2018 in Jira Service Desk

A is for Activate: Share your top Jira Service Desk onboarding tips for new users!

Hi, everyone! Molly here from the Jira Service Desk Product Marketing Team :).  In the spirit of this month's  august-challenge, we're sourcing stories of Jira Service Desk activation fro...

580 views 25 15
Join discussion

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