Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Create a sub-tasks using scriptrunner

vitorv
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!
November 7, 2018

Im trying to create a sub-task with scriptrunner, i followed the instructions from this link "https://developer.atlassian.com/server/jira/platform/performing-issue-operations/".

 

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.setLevel(Level.DEBUG)

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.setProjectId((long)12512);
issueInputParameters.setIssueTypeId("131");
issueInputParameters.setSummary("This is a summary");
issueInputParameters.setDescription("I am a description");
issueInputParameters.setSecurityLevelId((long)10740);
issueInputParameters.setSkipScreenCheck(true);
issueInputParameters.setApplyDefaultValuesWhenParameterNotProvided(true)


log.error("Estou imputando parametros")

issueInputParameters.setSkipScreenCheck(true);
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(createValidationResult.getErrorCollection())

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(createResult.getErrorCollection())
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.")
}
}
else
{
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 like:log.info("...") 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

Suggest an answer

Log in or Sign up to answer
1 vote
Answer accepted
Joshua Yamdogo @ Adaptavist
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 8, 2018

Hi,

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:

https://library.adaptavist.com/entity/create-a-subtask-and-link-to-parent-issue-in-jira

Regards,

Josh

TAGS
AUG Leaders

Atlassian Community Events