Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

[JIRA] Auto transition between parent and sub task

Rowens Hsu March 31, 2013

How to implement auto transition between parent and sub task?

The workflow of parent issue has a tranistion called planning : define problem --> planned

And worflow steps before planned are : Open --> define problem --> planned

If the parent issue go through this transition,

I want the subtask (all issues linke to the parent issue) tranfer from open --> planned , and define problem --> planned.

How to achieve this?

P.S. Status "define problem" and "planned" are not jira-default status.

Thanks.

5 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

0 votes
Answer accepted
Rowens Hsu April 1, 2013

Not a very good solution, but it works:

Use a custom event listener to achieve parent's trigger on subtask transition.

1. Add a custem event. (Say, eventId = "99999" You can look it up from jiraeventtype table.)

2. Set post-function of parent's transition to fire the custom event added at step 1.

3. Add custom event listener.

import java.util.Collection;
import com.atlassian.jira.ComponentManager;
import com.atlassian.jira.config.SubTaskManager;
import com.atlassian.jira.event.issue.AbstractIssueEventListener;
import com.atlassian.jira.event.issue.IssueEvent;
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.issue.MutableIssue;
import com.atlassian.jira.issue.issuetype.IssueType;
import com.atlassian.jira.util.JiraUtils;
import com.atlassian.jira.workflow.WorkflowTransitionUtil;
import com.atlassian.jira.workflow.WorkflowTransitionUtilImpl;

public class TransitionListener extends AbstractIssueEventListener {
@Override
public void customEvent(IssueEvent event) { // listen all custom event
Issue parent = event.getIssue();
String eventId = Long.toString(event.getEventTypeId());
if ("99999".equals(eventId)) { // listen to specific custom event added at step 1
try {
WorkflowTransitionUtil workflowTransitionUtil = (WorkflowTransitionUtil) JiraUtils.loadComponent(WorkflowTransitionUtilImpl.class);
SubTaskManager subTaskManager = ComponentManager.getInstance().getSubTaskManager();
Collection<MutableIssue> subTasks = subTaskManager.getSubTaskObjects(parent);
for (MutableIssue subTask : subTasks) {
workflowTransitionUtil.setIssue(subTask);
workflowTransitionUtil.setAction(11); // subtask's action id --Trigger subTask's transition
workflowTransitionUtil.validate();
workflowTransitionUtil.progress();
}
} catch (Exception e) {
e.printStackTrace();
}
}
}

}

0 votes
Fidel Castro
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.
September 28, 2014

JIRA Workflow Toolbox plugin can be used to make any linked issues, subtasks, JQL selected issues and parent issue progress through its workflow. You can check how to do it at documentation site:

0 votes
Rowens Hsu March 31, 2013

https://marketplace.atlassian.com/plugins/com.innovalog.jmwe.jira-misc-workflow-extensions

I found JIRA-MISC-WORKFLOW-EXTENSIONS's "Transition Parent Issue" can achieve part of my requirement. However, it only permits child's trigger on parent transition, not the other way around.

Put it another way, how can we achieve dual transition trigger between parent and sub-task?

0 votes
Tansu Kahyaoglu March 31, 2013

Or you can use Script Runner(https://marketplace.atlassian.com/plugins/com.onresolve.jira.groovy.groovyrunner) by writing your own script and adding it as post function

Rowens Hsu March 31, 2013

Can you be more specific of what related api on transition triggering is ? Thanks.

Tansu Kahyaoglu April 1, 2013

here is the post function groovy script. Change transition id and link type if you need. This is for linked issues you can change it to subtask.

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.workflow.WorkflowTransitionUtil;
import com.atlassian.jira.workflow.WorkflowTransitionUtilImpl;
import com.atlassian.jira.util.JiraUtils;
import com.atlassian.jira.issue.link.IssueLink;
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.IssueFieldConstants
import com.atlassian.jira.issue.index.IssueIndexManager
import com.atlassian.jira.util.BuildUtils
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.util.ImportUtils

IssueIndexManager indexManager = ComponentManager.getInstance().getIndexManager()
def Category log = Category.getInstance("com.onresolve.jira.groovy.PostFunction")
log.setLevel(org.apache.log4j.Level.DEBUG) 

String currentUser = ((WorkflowContext) transientVars.get("context")).getCaller();
WorkflowTransitionUtil workflowTransitionUtil = ( WorkflowTransitionUtil)JiraUtils.loadComponent( WorkflowTransitionUtilImpl.class );

linkType = "duplicates"

linkMgr = ComponentManager.getInstance().getIssueLinkManager()
for (IssueLink link in linkMgr.getInwardLinks(issue.id)) {

if (linkType == link.issueLinkType.name) {
Issue dup = link.sourceObject;
workflowTransitionUtil.setIssue(dup)
workflowTransitionUtil.setUsername(currentUser)
workflowTransitionUtil.setAction (111)

workflowTransitionUtil.validate();
workflowTransitionUtil.progress(); boolean wasIndexing = ImportUtils.isIndexIssues(); ImportUtils.setIndexIssues(true); if ((BuildUtils.getCurrentBuildNumber() as Long) < 614) {
ManagerFactory.getCacheManager().flush(com.atlassian.jira.issue.cache.CacheManager.ISSUE_CACHE, issue)
} indexManager.reIndex(issue); indexManager.reIndex(dup); ImportUtils.setIndexIssues(wasIndexing); }
}

0 votes
Florin Manaila
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 31, 2013

Hi Rowens,

You can do that using the JJupin pulgin. Here is a tutorial http://confluence.kepler-rominfo.com/display/TR/Autotransitioning+subtasks

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

TAGS
AUG Leaders

Atlassian Community Events