Jira (7.7 - 8.6)
import com.atlassian.jira.component.ComponentAccessor
import com.onresolve.scriptrunner.canned.jira.utils.ConditionUtils
import com.onresolve.scriptrunner.canned.jira.workflow.postfunctions.CloneIssue
import com.onresolve.scriptrunner.runner.ScriptRunnerImpl
def projectKey = "Project Key" //Replace with the key of the project you want to copy to
def issueKey = "Issue Key" //Replace with the key of the issue you want to copy
def projectManager = ComponentAccessor.projectManager
def issueManager = ComponentAccessor.issueManager
def projectToCopyTo = projectManager.getProjectByCurrentKey(projectKey)
def issueToCopy = issueManager.getIssueObject(issueKey)
// Block creation of intra-project links
def blockIntraprojectLinks = '{l -> l.sourceObject.projectObject != l.destinationObject.projectObject}'
if (!issueToCopy) {
log.warn("Issue ${issueKey} does not exist")
return
}
//Set the creation parameters/inputs (use clone issue but with no link type)
def inputs = [
(CloneIssue.FIELD_TARGET_PROJECT) : projectToCopyTo.key,
(CloneIssue.FIELD_LINK_TYPE) : null,
(ConditionUtils.FIELD_ADDITIONAL_SCRIPT): [
"checkLink = $blockIntraprojectLinks;",
""
],
(CloneIssue.FIELD_SELECTED_FIELDS) : null, //clone all the fields
(CloneIssue.SKIP_EPIC_LINKS) : "true",
] as Map
def executionContext = [issue: issueToCopy] as Map
def newClonedIssue = ScriptRunnerImpl.scriptRunner.createBean(CloneIssue)
// Execute the clone action with the specified inputs
def updatedExecutionContext = newClonedIssue.execute(inputs, executionContext)
//The issue has been successfully cloned
assert updatedExecutionContext.newIssue