Is there a way that I can configure Jira to create automatic sub-tasks based on a custom field drop down selection?

Vishali
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.
May 6, 2013

I have a drop-down with values - Receptionist, HR, IT etc.,
If receptionist is chosen from the drop-down, few sub-tasks configured for that role should be created (not all)
If HR is chosen from the drop-down, few sub-tasks configured for that role should be created (not all)
If IT is chosen from the drop-down, few sub-tasks configured for that role should be created (not all)

May I know how to configure this in Jira?

3 answers

1 accepted

0 votes
Answer accepted
Vishali
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.
May 7, 2013

import com.atlassian.jira.ComponentManager;
import com.atlassian.jira.issue.CustomFieldManager;
import com.atlassian.jira.issue.fields.CustomField;
import com.atlassian.jira.issue.MutableIssue;
import org.apache.log4j.Category;
import com.atlassian.jira.util.ImportUtils
import com.atlassian.jira.issue.fields.config.FieldConfig;
import com.opensymphony.workflow.WorkflowContext;
import com.atlassian.jira.issue.IssueManager;
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder;
import com.atlassian.jira.issue.ModifiedValue;
import com.atlassian.jira.issue.customfields.manager.OptionsManager
import com.atlassian.jira.issue.IssueImpl

CustomFieldManager cfm = ComponentManager.getInstance().getCustomFieldManager();
issueManager = ComponentManager.getInstance().getIssueManager()
issueFactory = ComponentManager.getInstance().getIssueFactory()
authenticationContext = ComponentManager.getInstance().getJiraAuthenticationContext()
subTaskManager = ComponentManager.getInstance().getSubTaskManager()
MutableIssue myIssue = issue
log = Category.getInstance("com.onresolve.jira.groovy.PostFunction")

CustomField cfAutoID = cfm.getCustomFieldObject("customfield_12131");
def autoID = myIssue.getCustomFieldValue(cfAutoID);
log.info("Custom field value -"+autoID);

def addSubTask(issueTypeId, subTaskName) {
log.error("Adding subTask: " + subTaskName)
def issueObject = issueFactory.getIssue()
issueObject.setProject(issue.getProject())
issueObject.setIssueTypeId(issueTypeId)
issueObject.setParentId(issue.getId())
issueObject.setSummary(subTaskName)
issueObject.setAssignee(issue.getAssignee())
issueObject.setDescription(subTaskName)
issueObject.setReporter(issue.getReporter())

subTask = issueManager.createIssue(authenticationContext.getUser(), issueObject)
log.error("issue.getGenericValue(): " + issue.getGenericValue())
subTaskManager.createSubTaskIssueLink(issue.getGenericValue(), subTask, authenticationContext.getUser())

// Once all the subtasks have been created
// Update search indexes
ImportUtils.setIndexIssues(true);
ComponentManager.getInstance().getIndexManager().reIndex(subTask)
ImportUtils.setIndexIssues(false)
}
switch(autoID) {
case "Every User / Standard Setup" :
addSubTask("5",'Please setup ABCD');
addSubTask("5",'Please setup DCBA');
addSubTask("5",'Please provide XYZ');
break;

case "HR" :
addSubTask("5",'Please start Payroll');
addSubTask("5",'Please setup account');

default:
addSubTask("5",'Please setup ABCD');
}

Vishali
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.
May 7, 2013

However, each of the sub-task should be assigned to a different assignee. Also, I need certain parent fields to be copied over to sub-task. How can I achieve this?

Vishali
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.
June 17, 2013

I have added this

switch(subTaskName) {
case "Please setup ABCD" :
issueObject.setAssignee(username)
break;
}

0 votes
Bob Swift OSS (Bob Swift Atlassian Apps)
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.
May 6, 2013

If you want to do this as part of a workflow transition, then Create on Transition Plugin for JIRA will do that.

Vishali
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.
May 6, 2013

Bob,

I am already using your plugin from long time. Very helpful plugin.

But in this case, I have around 14 custom field drop down options and 23 sub-tasks out of which only certain of them get created based on the drop down selection. As the list might get too huge with your plugin, I was looking for other options like scripting. Is there a way that I can shrink them into very less number of actions using 'Create sub-task on transition'?

Bob Swift OSS (Bob Swift Atlassian Apps)
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.
May 6, 2013

Sounds like a custom script is necessary if there are so many combinations.

0 votes
Timothy
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.
May 6, 2013

There's no configuration of this source out of the box for JIRA.

Some alternatives include running a Jelly script to execute on a filter to create a subtask or using a remote API to create this.

Vishali
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.
May 6, 2013

Based on online references, I am planning to user Scriptrunner for this. Any idea on how to do the customization based on custom field value selection?

Suggest an answer

Log in or Sign up to answer