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

How to clone issue without issuelink through scriptrunner

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

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-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
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.

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-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
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