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

Why does script end when running createIssueObject()? Edited

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 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.";
}

2 answers

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?

Cheers!

DY

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.

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)
log.debug("hello")
Map<String,Object> newIssueParams = ["issue":newIssue] as Map<String,Object>
log.debug("after hello")
issueManager.createIssueObject(currentUser, newIssueParams)
//def cloned = issueManager.createIssueObject(currentUser, newIssueParams)

log.debug("bollo")

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

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Marketplace Apps & Integrations

Staying organized with Jira: best practices for a better project management

Project managers know this problem: A “mountain of work” lays in front of you, and you don’t know how and where to tackle them. Different to-dos lie ahead, but just one task after the other can be ha...

246 views 2 1
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