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

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

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

This widget could not be displayed.

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

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?

I have added this

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

This widget could not be displayed.
Timothy Chin Community Champion May 06, 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.

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?

This widget could not be displayed.

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

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'?

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

Suggest an answer

Log in or Sign up to answer
Atlassian Summit 2018

Meet the community IRL

Atlassian Summit is an excellent opportunity for in-person support, training, and networking.

Learn more
Community showcase
Posted Aug 06, 2018 in Jira Service Desk

A is for Activate: Share your top Jira Service Desk onboarding tips for new users!

Hi, everyone! Molly here from the Jira Service Desk Product Marketing Team :).  In the spirit of this month's  august-challenge, we're sourcing stories of Jira Service Desk activation fro...

528 views 23 15
Join discussion

Atlassian User Groups

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

Find a group

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

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you