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

Your Points Tracker
Challenges
Leaderboard
  • 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
Recognition
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?
Kudos
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

Create a sub-tasks using scriptrunner

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

0 votes
Answer accepted

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

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase

The benefits of using Jira in different departments

Jira is a great tool to use across different departments. Forget that paperwork – switch to Jira and get that tasks done smoothly. Marketing Jira allows for a complete digital transformation of you...

109 views 0 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