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 votes

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 Sign up to answer
Community showcase
Published Jan 08, 2019 in Jira

How to Jira for designers

I’m a designer on the Jira team. For a long time, I’ve fielded questions from other designers about how they should be using Jira Software with their design team. I’ve also heard feedback from other ...

808 views 3 9
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