Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
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

Create a sub-tasks using scriptrunner

Im trying to create a sub-task with scriptrunner, i followed the instructions from this link "".


the issue was create but not as a sub-task, i don't know what im doing wrong.


im using the method "issueService.validateSubTaskCreate(user,issueId,issueInputParameters);" passing parent issue ID.


The script that im using is:


import com.atlassian.jira.component.ComponentAccessor
import java.util.Random;
import com.atlassian.jira.issue.IssueManager;
import com.atlassian.jira.issue.*;
import com.atlassian.jira.project.*;
import com.atlassian.jira.bc.project.component.*;
import com.atlassian.jira.issue.MutableIssue;
import com.atlassian.jira.event.type.*;
import com.atlassian.jira.issue.fields.CustomField;
import com.atlassian.jira.bc.issue.IssueService
import com.atlassian.jira.bc.issue.IssueService.CreateValidationResult
import com.atlassian.jira.bc.issue.IssueService.IssueResult
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.IssueInputParameters
import com.atlassian.jira.user.ApplicationUser
import org.apache.commons.lang3.StringUtils
import com.atlassian.jira.ComponentAccessor.*
import com.atlassian.jira.issue.IssueInputParameters.addCustomFieldValue.*
import org.apache.log4j.Logger
import org.apache.log4j.Level

def log = Logger.getLogger("com.acme.CreateSubtask")

log.debug "foo bar"

IssueService issueService = ComponentAccessor.getIssueService();
log.error("Estou instanciando o issue service")
long projectId =12512
long AdquirenteId = 19728
long BancoId = 19821

IssueInputParameters issueInputParameters = issueService.newIssueInputParameters();
issueInputParameters.setSummary("This is a summary");
issueInputParameters.setDescription("I am a description");

log.error("Estou imputando parametros")

log.error("Estou inputando Skipando Validação")
ApplicationUser user = ComponentAccessor.getJiraAuthenticationContext().getUser()
long issueId = issue.getId()


log.error("Estou Criando a subtask")
CreateValidationResult createValidationResult = issueService.validateSubTaskCreate(user,issueId,issueInputParameters);
log.error("Estou criando uma subtarefa")
log.error("issue input parameters: " + issueInputParameters.getActionParameters())

log.error("Validation?:" + createValidationResult.isValid().toString())

if (createValidationResult.isValid())
log.error("i am in createValidationResult")
log.error("will be created")
log.error("Criando a issue demonio")
IssueResult createResult = issueService.create(
user, createValidationResult)

log.error("Creation result?: {}" + createResult.isValid().toString())

log.error("created ")
log.error("DESCRIPTION OF CREATED ISSUE: " + createResult.getIssue().getDescription() + createResult.getIssue().getKey())

if (!createResult.isValid())
log.error("Error while creating the issue.")
String cause = StringUtils.join(createValidationResult.getErrorCollection().getErrorMessages(), "/")
log.error("cause :" + cause)



And the log of an try is:


  • Logs
  • Payload
  • Timing

Time (on server): Wed Nov 07 2018 13:45:53 GMT-0200 (Horário de Verão de Brasília)

The following log information was produced by this execution. Use statements"...") to record logging information.

2018-11-07 13:45:53,338 DEBUG [acme.CreateSubtask]: foo bar
2018-11-07 13:45:53,340 ERROR [acme.CreateSubtask]: Estou instanciando o issue service
2018-11-07 13:45:53,340 ERROR [acme.CreateSubtask]: Estou imputando parametros
2018-11-07 13:45:53,340 ERROR [acme.CreateSubtask]: Estou inputando Skipando Validação
2018-11-07 13:45:53,341 ERROR [acme.CreateSubtask]: Estou Criando a subtask

2018-11-07 13:45:53,368 ERROR [acme.CreateSubtask]: Estou criando uma subtarefa 2018-11-07 13:45:53,368 ERROR [acme.CreateSubtask]: issue input parameters: [summary:[This is a summary], issuetype:[131], security:[10740], description:[I am a description], pid:[12512]] 2018-11-07 13:45:53,368 ERROR [acme.CreateSubtask]: Errors: {} Error Messages: [] 2018-11-07 13:45:53,368 ERROR [acme.CreateSubtask]: Validation?:true 2018-11-07 13:45:53,368 ERROR [acme.CreateSubtask]: i am in createValidationResult 2018-11-07 13:45:53,368 ERROR [acme.CreateSubtask]: will be created 2018-11-07 13:45:53,368 ERROR [acme.CreateSubtask]: Criando a issue demonio








1 answer

1 accepted


We have an example script on our new website of how to programmatically create a sub-task for a parent issue. See the script here:



Suggest an answer

Log in or Sign up to answer
Community showcase
Published in Apps & Integrations

Send an Email or Publish to Confluence - What should you do with your release notes?

Background When you hear the words ‘Release notes’, almost always you think of an unsolicited email from a software vendor. But I am here to tell you that from our data, sending release notes via E...

122 views 1 2
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