How can I generate multiple sub-tasks as a Groovy Post Function of a Create Transition

When a user creates an issue that with the summary "Markup Master Task - X issues", I'd like to automatically create X number of SubTasks.

ScriptRunner has an option to create a single sub-task on a transition, but I'm looking for something to create multiple sub-tasks rather than manually add a bunch of separate Post Functions.

Here's what I have so far as a Custom Script Post Function for a Create Issue transition. Any help is appreciated!

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

def parentIssue = sourceIssue
int numMarkups

doAfterCreate = {

if (parentIssue.getIssueType().getName() != 'Task')

if (parentIssue.summary.contains("Markup Master Task"))
numMarkups = Integer.parseInt(parentIssue.summary);

if (numMarkups >= 50)
def i = 0
def issueFactory = ComponentAccessor.getIssueFactory()
def subTaskManager = ComponentAccessor.getSubTaskManager()
def constantManager = ComponentAccessor.getConstantsManager()
def issueManager = ComponentAccessor.getIssueManager()

for (i; i < numMarkups; i++)
MutableIssue newSubTask = issueFactory.getIssue()
newSubTask.setSummary("Markup" + i.toString())
newSubTask.assignee == parentIssue.assignee
newSubTask.components == parentIssue.getComponents()

newSubTask.setPriorityId(constantManager.getPriorities().find {
it.getName() == "P2" }.id)


it.getName() == "Sub-task" }.id) }




1 answer


There's a few other questions up that already cover similar scripts to this:

Let me know if you still need help getting something to work after reading over the answers there. :)


Thank you @Jenna Davis! I've referenced both of the answers listed.

Both of the threads use this snippet at the bottom of their scripts, but it's throwing an error for me. Particularly, it's saying the word String is an "unexpected token" Any idea what's causing that? 


 Map&lt;String,Object&gt; newIssueParams = ["issue" : newSubTask] as Map&lt;String,Object&gt;
    issueManager.createIssueObject(user.directoryUser, newIssueParams)
    subTaskManager.createSubTaskIssueLink(parentIssue, newSubTask, user.directoryUser) "Issue with summary ${newSubTask.summary} and assignee ${assigneeId} created"


I was running into the same error, as i'm not a developer i had to look it up and I found the solution. Code is messed up by the website, this is how the line should look like:

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

Yeah, community likes to finagle the code a bit. The "&lt" and "&gt" are the html encodings for "<" (less-than) and ">" (greater-than).

Nice fix!

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Feb 07, 2019 in Marketplace Apps

A Timeless Love Story

It started as any story starts, on a normal, rainy day.   Admin meets App, and her name was Klok2, and like any first relationship we were both trying to make it work but neither one knew what...

465 views 8 27
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