It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

[JIRA] Auto transition between parent and sub task

Rowens Hsu Mar 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

0 votes
Answer accepted
Rowens Hsu Apr 01, 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
Florin Manaila Mar 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

0 votes
Tansu Kahyaoglu Mar 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 Mar 31, 2013

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

Tansu Kahyaoglu Apr 01, 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
Rowens Hsu Mar 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
Fidel Castro Sep 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:

Suggest an answer

Log in or Sign up to answer
This widget could not be displayed.
This widget could not be displayed.
Community showcase
Published in Next-gen

Introducing subtasks for breaking down work in next-gen projects

Teams break work down in order to help simplify complex tasks. This is often done iteratively, with tasks being broken down into smaller tasks and so on until the work is accurately captured in well-...

6,043 views 22 30
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you