You're on your way to the next level! Join the Kudos program to earn points and save your progress.
Level 1: Seed
25 / 150 points
Next: Root
1 badge earned
Challenges come and go, but your rewards stay with you. Do more to earn more!
What goes around comes around! Share the love by gifting kudos to your peers.
Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!
Join now to unlock these features and more
The Atlassian Community can help you and your team get more value out of Atlassian products and practices.
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:
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
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.