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

How to copy a subtask to another parent Issue?

Christian Selbrede
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.
June 5, 2012

I am writing a plugin that needs to copy the existing subtasks of an issue to a new parent issue.

I can easily get the original subtasks using:

for(Issue subtask : subtaskManager.getSubTaskObjects(originalIssue))
{
   // Iterating through subtasks
}

How can I create copies of these subtasks and attach each of them to a new parent Issue object?

2 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

0 votes
Answer accepted
Christian Selbrede
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.
June 20, 2012

And if you want to do it in a groovy way that's non-deprecated:

for (def subtask : subtaskManager.getSubTaskObjects(templateIssue)){

def parameters = issueService.newIssueInputParameters()
parameters.setSummary(subtask.getSummary())
parameters.setDescription(subtask.getDescription())
parameters.setAssigneeId(templateIssue.getAssigneeId())
parameters.setReporterId(templateIssue.getReporterId())
parameters.setProjectId(templateIssue.getProjectObject().getId())
parameters.setIssueTypeId(subtask.getIssueTypeObject().getId())
   
def result = issueService.validateSubTaskCreate(user, issue.getId(), parameters)
result = issueService.create(user, result)
subtaskManager.createSubTaskIssueLink(parent, result.getIssue(), user)

}

1 vote
Christian Selbrede
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.
June 6, 2012

For anyone else having the same question, here is my solution:

for(Issue i : subtaskManager.getSubTaskObjects(templateIssue))
{
   MutableIssue subtask = issueFactory.getIssue();

   subtask.setSummary(i.getSummary());
   subtask.setDescription(i.getDescription());
   subtask.setAssignee(i.getAssignee());
   subtask.setReporter(i.getReporter());
   subtask.setProject(myIssue.getProject());
   subtask.setIssueType(myIssue.getIssueType());

   try{
     issueManager.createIssueObject(issueEvent.getUser(), subtask);
     subtaskManager.createSubTaskIssueLink(myIssue, subtask, issueEvent.getUser());
   }
   catch(CreateException e)
   {
     log.error(e.getMessage());
   }
}

TAGS
AUG Leaders

Atlassian Community Events