Using scriptrunner I need to know how to create multiple subtasks as a postfunction


I need to know how to create muliplte subtasks as a postfunction through a workflow transition.

I have to create upwards of 20+ subtasks per workflow status and need to know how they can be automatically added through transitions.

Does anyone have any script that will be of assistance.

1 answer

0 vote
Joshua Yamdogo Community Champion Aug 09, 2017

Hi Rhian,

Do you need each of these sub-tasks to have different information? Or will all of the sub-tasks contain all of the same information? Creating sub-tasks automatically on a workflow function is already a feature built-in to ScriptRunner.

  1. Go to the workflow step you want to create sub-tasks on
  2. Click add Post Function
  3. Click Script Post Function
  4. Select "Create a sub-task"

Screen Shot 2017-08-09 at 8.29.08 AM.png

This built-in feature would work well if you need each sub-task to have different information, since you could customize each sub-task individually as a post-function. However, if you just need to create 20+ sub-tasks with the same information, you'd probably be better off with a post-function custom script like this:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.MutableIssue

def constantManager = ComponentAccessor.getConstantsManager()
def user = ComponentAccessor.getJiraAuthenticationContext().getUser()
def issueFactory = ComponentAccessor.getIssueFactory()
def subTaskManager = ComponentAccessor.getSubTaskManager()
def issueManager = ComponentAccessor.getIssueManager()

Issue parentIssue = issue

if (parentIssue.getIssueTypeObject().getName() == 'Sub-task')

if (parentIssue.getIssueTypeObject().name != 'Feature')

def summariesList = ["Summary 1", "Summary 2", "Summary 3"]

summariesList.each {
MutableIssue newSubTask = issueFactory.getIssue()
it.getName() == "Sub-task"
// Add any other fields you want for the newly created sub task

Map<String,Object> newIssueParams = ["issue" : newSubTask] as Map<String,Object>

//for JIRA v6.*
issueManager.createIssueObject(user.directoryUser, newIssueParams)
subTaskManager.createSubTaskIssueLink(parentIssue, newSubTask, user.directoryUser)
// for JIRA v7.*
issueManager.createIssueObject(user, newIssueParams)
subTaskManager.createSubTaskIssueLink(parentIssue, newSubTask, user) "Issue with summary ${newSubTask.summary} created"

Thanks for replying Joshua,


I need to have different subtasks at different stages of the transition however there will be many subtasks and I have been told that a custom script will be best for this.

I have tried the custom script you have provided however I am still getting a failed response:

unable to resolve class for:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.MutableIssue

Struggling to get a working script at the moment haha.

Suggest an answer

Log in or Join to answer
Community showcase
Sarah Schuster
Posted Jan 29, 2018 in Jira

What are common themes you've seen across successful & failed Jira Software implementations?

Hey everyone! My name is Sarah Schuster, and I'm a Customer Success Manager in Atlassian specializing in Jira Software Cloud. Over the next few weeks I will be posting discussion topics (8 total) to ...

3,181 views 13 19
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
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot