I have a Task that has a series of subtasks that I am using as a template to setup recurring tasks through the ScriptRunner Escalation Services.
The script does the following things:
- Clone the template issue
- Load the Template issue's subtasks into a Collection
- Loop through the Collection to create clones of the teamplate subtasks and set the parent object to the new clone of the template
The issue that I am having is everytime this command runs the script stops processing. I end up with a subtask created that has no parent, and non of the other subtasks are created. Why does the script end on the createIssueObject?
Issue clonedTask = issueManager.createIssueObject(subtask.getReporter(), newIssueParams);
Full script below
import com.atlassian.jira.issue.IssueFactory;
import com.atlassian.jira.issue.MutableIssue;
import com.atlassian.jira.issue.IssueManager;
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.issue.Issue;
import com.atlassian.jira.issue.link.IssueLink;
import java.text.SimpleDateFormat;
def date = new Date();
def sdf = new SimpleDateFormat("yyyy-MM-dd");
def authenticationContext = ComponentAccessor.getJiraAuthenticationContext();
def userManager = ComponentAccessor.getUserManager();
IssueManager issueManager = ComponentAccessor.getIssueManager();
IssueFactory issueFactory = ComponentAccessor.getIssueFactory();
authenticationContext.setLoggedInUser(userManager.getUserByName("SERVICEA_ACCOUNT");
Issue targetParent = issueManager.getIssueByCurrentKey("SPECIFIC_ISSUE_KEY");
def subtaskList = targetParent.getSubTaskObjects();
for (subtask in subtaskList) {
def subTaskManager = ComponentAccessor.getSubTaskManager();
def constantManager = ComponentAccessor.getConstantsManager();
MutableIssue newSubtask = issueFactory.getIssue();
newSubtask.setSummary(subtask.getSummary());
newSubtask.setParentObject(issueManager.getIssueByCurrentKey("SPECIFIC_ISSUE_KEY"));
newSubtask.setIssueType(subtask.getIssueTytpe());
newSubtask.setProjectObject(subtask.getProjectObject());
def newIssueParams = ["issue" : newSubtask] as Map<String,Object>;
issue clonedTask = issueManager.createIssueObject(subtask.getReporter(), newIssueParams);
//^ creates the subtask but it is not linked to a parent because processing stops. The code below does not run. WHY??
subTaskManager.createSubTaskIssueLink(issueManager.getIssueByCurrentKey("SPECIFIC_ISSUE_KEY")), clonedTask, subtask.getReporter();
log.info "subtask ${newSubtask.summary} created.";
}