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

How to auto create multiple subtasks in JIRA by groovy


How can I automatically creates few sub-tasks with fix summary I define for each subtasks on JIRA issue Creation  (Story / task any normal issue type) & also put quick check like if Template (Custom field - type select list single choice) = Template 1 then create sub-task else ignore.

Based on that I will put another post function with same script & check if Template = Template 2 then create sub task else ignore it.

I want to use groovy script for this as script runner is providing option to put inline groovy or file groovy.

Capture 2016-03-01 at 15.44.10.png


Currently I am able to create sub tasks based on Script runner post function "Create Sub task" but if I need to create 15 sub tasks then I need to add separate 15 PFs in workflow & if need to modify summary then again update 15 Post functions !!

Capture 2016-03-01 at 15.38.21.pngCapture 2016-03-01 at 15.39.55.png


So please suggest if you are using groovy for auto creating subtasks. I already searched old answers but as I am new to groovy I am not getting where to put name/id of my project & where to put name of my subtasks. also I need small check of custom field as I mentioned above. So please suggest on this.




2 answers

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

You want something like the following. Just check custom field values to see whether to create the sub-tasks or not:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.MutableIssue
def parentIssue = event.issue
if (parentIssue.getIssueType().getName() != 'New Employee')
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def summariesList = ["summary1",
def issueFactory = ComponentAccessor.getIssueFactory()
def subTaskManager = ComponentAccessor.getSubTaskManager()
def constantManager = ComponentAccessor.getConstantsManager()
def issueManager = ComponentAccessor.getIssueManager()
summariesList.each { subTaskSummary ->
    MutableIssue newSubTask = issueFactory.getIssue()
    newSubTask.setPriorityId(constantManager.getPriorities().find {
        it.getName() == "High"
        it.getName() == "Sub-task"
    // Add any other fields you want for the newly created sub task
    log.debug("New issue ${newSubTask}")
    Map<String,Object> newIssueParams = ["issue" : newSubTask] as Map<String,Object>
    issueManager.createIssueObject(user, newIssueParams)
    subTaskManager.createSubTaskIssueLink(parentIssue, newSubTask, user) "Issue with summary ${newSubTask.summary} created"

Hi Jamie, 


I'm looking to do something similar, but instead of creating a set number of subtasks I want to create X based on the value of a numeric field on the parent issue. The subtasks would inherit values from the parent for most fields. What would the script look like for something like that? 

I have tested the script and it works.

How can I modify it to replace the current list for summariesList by the selected values from a field type Checkboxes

Thank you in advance for your help

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.customfields.option.Option

def customFieldManager = ComponentAccessor.customFieldManager
def cf = customFieldManager.getCustomFieldObjectByName("My checkboxes field")
def summariesList = (issue.getCustomFieldValue(cf) as Collection<Option>)*.value

Hi Jamie,


This is awesome do you know if their is a way to have multiple field for one subtask.


For exemple.

I try to have multiple column to select from

C1 (Ressource) C2(Summary) C3(Estimate effort) C4 (Start Date) c5 (End Date)

The first one has multiple

C2 is a text box

C3 Is a number

C4-C5 are date picker


I want to be able to add mutliple line to create multiple subtaks....

Is this can be adapt to have this kind of setup

Community showcase
Posted in Industry Groups

Webinar alert: Managing Atlassian instances in modern government enterprises

Hi there, Atlassian Community! Government agencies count on Atlassian to help update their processes and help them hit their goals. As your team scales, it’s important to have an airtight, future-p...

34 views 1 2
View post

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