Are you in the loop? Keep up with the latest by making sure you're subscribed to Community Announcements. Just click Watch and select Articles.

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

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

Avatar

1 badge earned

Collect

Participate in fun challenges

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

Challenges
Coins

Gift kudos to your peers

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

Recognition
Ribbon

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!

Leaderboard

Scriptrunner - Clone subtask to a linked ticket from the parent ticket

Hi there,

I'm very new at Scriptrunner!

On a certain transition, I'm trying to clone and link a subtask from project B to an existing linked ticket on project A. Below is what I've been able to put together from my research. It works when I point it to a ticket in project B, but it does nothing when I point to a ticket in project A. The end goal is to have an exact clone of the parent and subtasks in projects A & B that are linked to each other. 

 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.customfields.manager.OptionsManager
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.fields.CustomField
import org.apache.log4j.Logger
import org.apache.log4j.Level
import com.atlassian.jira.project.Project
import com.onresolve.scriptrunner.canned.jira.workflow.postfunctions.CloneIssue
import com.atlassian.jira.issue.link.IssueLinkTypeManager
import com.atlassian.jira.issue.link.IssueLinkType
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.bc.project.component.ProjectComponent

def issueManager = ComponentAccessor.getIssueManager()
def issueFactory = ComponentAccessor.getIssueFactory()
def subtaskManager = ComponentAccessor.getSubTaskManager()
def issue = issueManager.getIssueObject("KW-2491") // parent issue
log.error("SOURCE ISSUE KEY: ${issue.getKey()}")
def subtasks = issue.getSubTaskObjects()
if (subtasks)
{
subtasks.each {subtask ->
def toclone = issueFactory.cloneIssueWithAllFields(subtask)
def cloned = issueManager.createIssueObject(issue.reporter, toclone)
subtaskManager.createSubTaskIssueLink(issue, cloned, issue.reporter)
log.error("CLONED ISSUE KEY: ${cloned.getKey()}")
}
}

0 answers

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events