Create JIRA sub-tasks automatically when issue created
Asked Answered
N

4

12

I am wondering there is a way to create sub-tasks automatically when issue created.

For example, I create a custom Standard Issue Type, XXX, and Sub-tasks Issue Type YYY and ZZZ. When I create a issue with type XXX, then two sub-tasks with respective issue type YYY and ZZZ will be created automatically.

Nonu answered 4/6, 2012 at 1:32 Comment(0)
G
11

You could so this easily using Jira Scripting Suite by using post function on issue creation transition on the project's workflow. Sample code:

from com.atlassian.jira.util import ImportUtils
from com.atlassian.jira import ManagerFactory
from com.atlassian.jira.issue import MutableIssue
from com.atlassian.jira import ComponentManager
from com.atlassian.jira.issue.link import DefaultIssueLinkManager
from org.ofbiz.core.entity import GenericValue;

# get issue objects
issueManager = ComponentManager.getInstance().getIssueManager()
issueFactory = ComponentManager.getInstance().getIssueFactory()
authenticationContext = ComponentManager.getInstance().getJiraAuthenticationContext()
subTaskManager = ComponentManager.getInstance().getSubTaskManager();
issueLinkManager = ComponentManager.getInstance().getIssueLinkManager()
customFieldManager = ComponentManager.getInstance().getCustomFieldManager()
userUtil = ComponentManager.getInstance().getUserUtil()

# define subtask
issueObject = issueFactory.getIssue()
issueObject.setProject(issue.getProject())
issueObject.setIssueTypeId("5") # normal subtask
issueObject.setParentId(issue.getId())

# set subtask attributes
issueObject.setFixVersions(issue.getFixVersions())
issueObject.setAffectedVersions(issue.getAffectedVersions())
issueObject.setPriority(issue.getPriority())
issueObject.setSummary("Auto created sub task- "+issue.getSummary())
issueObject.setAssignee(userUtil.getUserObject("joe"))

# Create subtask on JIRA 4.x
# subTask = issueManager.createIssue(authenticationContext.getUser(), issueObject)
# subTaskManager.createSubTaskIssueLink(issue.getGenericValue(), subTask, authenticationContext.getUser())

# Create subtask on JIRA 5 and higher
subTask = issueManager.createIssueObject(authenticationContext.getLoggedInUser(), issueObject)
subTaskManager.createSubTaskIssueLink(issue, subTask, authenticationContext.getLoggedInUser())

# Link parent issue to subtask   issueLinkManager.createIssueLink(issue.getId(),issueObject.getId(),10300,1,authenticationContext.getUser())

# Update search indexes
ImportUtils.setIndexIssues(True);
ComponentManager.getInstance().getIndexManager().reIndex(subTask)
ImportUtils.setIndexIssues(False)
Goatherd answered 4/6, 2012 at 7:8 Comment(0)
P
0

One thing to consider is what happens if the parent issue is closed before all the subtasks are closed. I would recommend putting in a hook to prompt the user to address all the subtasks before closing the issue.

Phenica answered 21/6, 2012 at 18:18 Comment(0)
K
0

I found an easy solution using the add-on Script Runner - http://isolasoftware.it/2014/01/08/create-an-issue-in-jira-with-predefined-sub-tasks/.

You don't have to write any code but just setup the Post Function "Create a sub-task" in the Workflow editor.

Kirwan answered 24/5, 2014 at 14:36 Comment(0)
Q
-1

Just create a ticket called "template" (with all the necessary subtasks) and copy/clone it whenever creating new instances.

Quest answered 1/8, 2014 at 5:50 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.