• 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

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

0 vote
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?

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
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published Monday in Jira Software

How large do you think Jira Software can grow?

Hi Atlassian Community! My name is Shana, and I’m on the Jira Software team. One of the many reasons this Community exists is to connect you to others on similar product journeys or with comparabl...

727 views 6 13
Read article

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