How to clone issue without issuelink through scriptrunner

Vincent Lee May 12, 2020

Hi, 

I want to clone issue which have issuelink to other issue such as "contain(WBS)", "contained in(WBS)" while trainsition issue. 

The part of my code is as follow

import com.atlassian.jira.component.ComponentAccessor
import com.onresolve.scriptrunner.canned.jira.utils.AbstractCloneIssue
import com.onresolve.scriptrunner.canned.jira.utils.CannedScriptUtils
import com.onresolve.scriptrunner.canned.jira.utils.ConditionUtils
import com.onresolve.scriptrunner.canned.jira.workflow.postfunctions.CloneIssue
import com.onresolve.scriptrunner.runner.ScriptRunnerImpl


def TargetIssueType = null


def blockIntraprojectLinks = '{link -> false}'
def params = [
(CloneIssue.FIELD_TARGET_ISSUE_TYPE) : TargetIssueType,
(CloneIssue.FIELD_COPY_FIELDS) : AbstractCloneIssue.COPY_ALL_FIELDS,
(CloneIssue.FIELD_SELECTED_FIELDS) : null,
(CloneIssue.FIELD_COPY_COMMENTS) : false,
(CloneIssue.FIELD_USER_KEY) : null,
(ConditionUtils.FIELD_ADDITIONAL_SCRIPT): ["checkLink = $blockIntraprojectLinks;",""]
] as Map<String, Object>
def executionContext = [issue: originalIssue] as Map<String, Object>
def cloneIssueAction = ScriptRunnerImpl.scriptRunner.createBean(CloneIssue)

def updatedExecutionContext = cloneIssueAction.execute(params, executionContext)
def newIssue = updatedExecutionContext.newIssue

return newIssue

  

 but it still clone all issue information include all issuelink.

 

I also used IssueService showed in below url to clone issue, and set "cloneLinks = false"

https://library.adaptavist.com/entity/clone-issues-or-parts-of-issues-in-jira

It still copy all issuelink too.

 

Does anyone knows how to clone issue without issuelink?

Thanks a lot! 

3 answers

1 vote
Vincent Lee May 19, 2020

Hi @Nic Brough -Adaptavist- ,

Thanks for reply.

I have one more question.

If I create an listenter that catches "create issue" event. how to see if this event issue is created by my clone or not.

 

Thanks

Vincent

Nic Brough -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.
May 19, 2020

You'll need to have something in the new issue that you can tell the listener to look for as identifying it as a clone. 

A really obvious, but slightly clunky trick is to have a field that you set when your clone code runs, the listener looks for it, and then clears it out!

But you might just want to look for "is a clone of" type links on the issue.

0 votes
Eugeny Chernyavsky
Contributor
November 7, 2023

Maybe you can try to exclude links where link source object is the same as your triggering object (I used project key to compare in my case):

def additionalCode = """

issue.setSummary("Cloned from: $originalIssueKey " + issue.getSummary())

checkLink = {link -> sourceObject.projectKey != $projectKeyValue}

"""

 

and clone issue with this checkLink

def params = [

(CloneIssue.FIELD_TARGET_PROJECT) : projectKeyValue,

(CloneIssue.FIELD_TARGET_ISSUE_TYPE) : null,

(CloneIssue.FIELD_COPY_FIELDS) : AbstractCloneIssue.COPY_ALL_FIELDS,

(CloneIssue.FIELD_SELECTED_FIELDS) : null,

(CloneIssue.FIELD_COPY_COMMENTS) : false,

(ConditionUtils.FIELD_ADDITIONAL_SCRIPT): [additionalCode, ""],

(CloneIssue.FIELD_LINK_TYPE) : linkBetweenIssues,

(CloneIssue.FIELD_USER_KEY) : null

] as Map<String, Object>
0 votes
Nic Brough -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.
May 12, 2020

You can't.  The clone process makes a copy of all the core fields, including links. 

Best you can do is write a second listener that catches the "create issue" event, scans it to see if it has links and was created by your clone, and if it was, strip the links from it.

Suggest an answer

Log in or Sign up to answer