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

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

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();
}
}
}

}

Hi Rowens,

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

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

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

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); }
}

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?

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
Community showcase
Published in Jira Service Desk

[ Survey ] What does the future of ITSM look like? Take our survey today!

Hi all! We’re interested in learning more about your ITSM practices - what’s the current state of your ITSM practices? What are your aspirations for your IT team in the future? Which ITSM trends ar...

32 views 0 2
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