Forums

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

Using Post function script to Transition Sub-Tasks

pmooresaxton March 2, 2014

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

2 votes
Answer accepted
Henning Tietgens
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.
March 3, 2014

See my answer here.

pmooresaxton March 3, 2014

Thanks Henning. This works a treat.

Suggest an answer

Log in or Sign up to answer
TAGS
atlassian, likes for trees, atlassian community, social impact, tree planting campaign, community kudos, atlassian giving, environmental impact, sustainability, likes for good, atlassian social responsibility, community challenge

Make every click count—help us plant 50,000 trees! 🌳

Want to make your everyday Community actions directly contribute to reforestation? The Atlassian Community can achieve this goal by liking a post, attending an ACE, sending your peers kudos, and so much more!

Help us plant more trees
AUG Leaders

Atlassian Community Events