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

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root


1 badge earned


Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!


Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.


Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!


Why does script end when running createIssueObject()?


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:

  1. Clone the template issue
  2. Load the Template issue's subtasks into a Collection
  3. 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 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();


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();


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(); "subtask ${newSubtask.summary} created.";

2 answers

Suggest an answer

Log in or Sign up to answer

Accidental post.

@Cody McDaniels  / @Daniel Yelamos [Adaptavist] 

I am trying to clone issue with below code, 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.customfields.option.LazyLoadedOption
import com.atlassian.jira.issue.MutableIssue

def issueManager = ComponentAccessor.getIssueManager()
def issueFactory = ComponentAccessor.getIssueFactory()
def subtaskManager = ComponentAccessor.getSubTaskManager()
def issue = issueManager.getIssueObject("SWBLD-341710")
log.error("SOURCE ISSUE KEY: ${issue.getKey()}")

def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()

def newIssue = issueFactory.cloneIssueWithAllFields(issue)
Map<String,Object> newIssueParams = ["issue":newIssue] as Map<String,Object>
log.debug("after hello")
issueManager.createIssueObject(currentUser, newIssueParams)
//def cloned = issueManager.createIssueObject(currentUser, newIssueParams)


It is creating issue with the date of cloned issue. Is there anyway that issue can be created with current date

0 votes
Daniel Yelamos [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.
Sep 24, 2018

Hi Cody!

This is most likely related to a code exception, which means that your code is failing, not catching an exception, and hence, the execution is stopped. 

Have you checked the code for an exception?



Oops - I meant to reply.


 Thanks Daniel.

That is why I am so stumped- There are no exceptions. I put the entire script into a try-catch block and no exception gets thrown. The script just ends and reports that is completed successfully.

AUG Leaders

Atlassian Community Events