Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

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

Jason Stein
August 28, 2020

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 = componentIterator.next()
String componentName = component.getString("name");
String componentId = component.getString("id");

createSubtask(issue);
}

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()
issueInputParameters
.setProjectId(parentIssue.projectId)
.setIssueTypeId(subtaskIssueType.id)
.setSummary(parentIssue.summary+'- **'+componentName)
.setComponentIds(componentId)
//.setDescription('A description')
.setReporterId(asUser.key)

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

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

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

 

1 answer

0 votes
Kristin Huang
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
October 21, 2015

hi Simon, did you find an answer now? I am also looking for the solution

Suggest an answer

Log in or Sign up to answer