Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Deleted user
0 / 0 points
badges earned

Your Points Tracker
  • Global
  • Feed

Badge for your thoughts?

You're enrolled in our new beta rewards program. Join our group to get the inside scoop and share your feedback.

Join group
Give the gift of kudos
You have 0 kudos available to give
Who do you want to recognize?
Why do you want to recognize them?
Great job appreciating your peers!
Check back soon to give more kudos.

Past Kudos Given
No kudos given
You haven't given any kudos yet. Share the love above and you'll see it here.

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

Using Scriptrunner, I'm trying to automate the creation of a set of subtasks.

I want a set of subtasks created, which are the components of the parent.  So, if I have a Parent issue with 3 component names of "X", "A" and "B", then I want 3 subtasks created for that jira.

Here's my code at this point, but it's not working:

(I've put it into a Post-function.)

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

def issue = event.issue

Collection components = issue.getComponents();
Iterator componentIterator = components.iterator();
while (componentIterator.hasNext()) {
component =
String componentName = component.getString("name");
String componentId = component.getString("id");


def createSubtask(Issue parentIssue) {
def subTaskManager = ComponentAccessor.subTaskManager
def asUser = ComponentAccessor.jiraAuthenticationContext.loggedInUser
def constantsManager = ComponentAccessor.constantsManager
def issueService = ComponentAccessor.issueService
def subtaskIssueType = constantsManager.allIssueTypeObjects.findByName("Approval Sub-task")
def issueInputParameters = new IssueInputParametersImpl()
.setSummary(parentIssue.summary+'- **'+componentName)
//.setDescription('A description')

def createValidationResult = ComponentAccessor.issueService.validateSubTaskCreate(asUser,, issueInputParameters)

if (!createValidationResult.valid) {
log.error createValidationResult.errorCollection

def newIssue = issueService.create(asUser, createValidationResult).issue
subTaskManager.createSubTaskIssueLink(parentIssue, newIssue, asUser)


1 answer

1 accepted

1 vote
Answer accepted
Kevin Johnson Community Leader Aug 29, 2020

@Jason Stein This should work. Make sure it's in post-function before "Re-index an issue to keep indexes in sync with the database."

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.customfields.manager.OptionsManager
import com.atlassian.jira.user. ApplicationUser
import com.atlassian.jira.issue.IssueInputParametersImpl
import com.atlassian.jira.bc.project.component.ProjectComponent

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

Issue parentIssue = issue

if (parentIssue.getIssueType().name == 'Task')
Collection components = issue.getComponents();

//def customFieldManager = ComponentAccessor.getCustomFieldManager()
//def data = customFieldManager.getCustomFieldObject('customfield_10488')
//def listq = issue.getCustomFieldValue(data)

components.each {
MutableIssue newSubTask = issueFactory.getIssue()
it.getName() == "Sub-task"

def newIssueParams = ["issue" : newSubTask] as Map

issueManager.createIssueObject(user, newIssueParams)
subTaskManager.createSubTaskIssueLink(parentIssue, newSubTask, user) "Issue with summary ${newSubTask.summary} created"

Suggest an answer

Log in or Sign up to answer
Community showcase
Published in Jira Service Management

JSM June Challenge #2: Share how your business teams became ITSM rockstars

For JSM June Challenge #2, share how your non-technical teams like HR, legal, marketing, finance, and beyond started using Jira Service Management! Tell us: Did they ask to start using it or...

335 views 9 7
Read article

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