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

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,557,459
Community Members
 
Community Events
184
Community Groups

ScriptRunner CloneIssue not calling ADDITIONAL_SCRIPT

Hello!

I am trying to write a ScriptRunner groovy script that clones an issue. Eventually this will be a post-function that clones to multiple projects, but baby steps. 

As a test, here's my script that clones a hard-coded issue to another project.

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.link.IssueLinkTypeManager
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.MutableIssue
import com.onresolve.scriptrunner.canned.jira.workflow.postfunctions.CloneIssue
import com.onresolve.scriptrunner.canned.jira.utils.ConditionUtils
import org.apache.log4j.Logger
import com.atlassian.jira.issue.MutableIssue

def issue = ComponentAccessor.getComponent(IssueManager).getIssueByKeyIgnoreCase("SRC-1")
def clonesId = ComponentAccessor.getComponent(IssueLinkTypeManager).getIssueLinkTypes().findByName("Cloners")?.id

def cloneIssue = new CloneIssue()

def inputs = [
issue : issue,
(ConditionUtils.FIELD_ADDITIONAL_SCRIPT): """
issue.setSummary("CLONED: " + issue.getSummary())
checkLink = {link -> link.issueLinkType.name != "Cloners"}
""",

(CloneIssue.FIELD_COPY_COMMENTS) : true,
(CloneIssue.FIELD_TARGET_PROJECT) : "DEST",
(CloneIssue.FIELD_LINK_TYPE) : clonesId + " inward",
(CloneIssue.FIELD_SELECTED_FIELDS) : null, //clone all the fields
]

def errorCollection = cloneIssue.doValidate(inputs, false)
if (errorCollection.hasAnyErrors()) {
log.warn("Couldn't clone issue: ${errorCollection}")
}
else {
cloneIssue.doScript(inputs)
}

The issue does get cloned, but the ADDITIONAL_SCRIPT does not seem to get called. That is, the summary of the clone remains identical to the original, and all links are cloned.

Is there any trick to getting the ADDITIONAL_SCRIPT code to run?

 

1 answer

1 accepted

2 votes
Answer accepted
Joshua Yamdogo _ 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.
Jul 13, 2018

Hi Damon,

What version of SR are you on? You might try this instead:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.link.IssueLinkTypeManager
import com.onresolve.scriptrunner.canned.jira.utils.ConditionUtils
import com.onresolve.scriptrunner.canned.jira.workflow.postfunctions.CloneIssue

def issue = ComponentAccessor.getComponent(IssueManager).getIssueByKeyIgnoreCase("SRC-1")
def clonesId = ComponentAccessor.getComponent(IssueLinkTypeManager).getIssueLinkTypes().findByName("Cloners")?.id

def cloneIssue = new CloneIssue()

def additionalCode = """
issue.setSummary("CLONED: " + issue.getSummary())
checkLink = {link -> link.issueLinkType.name != "Cloners"}
"""

Map<String, Object> inputs = [
issue : issue,
(ConditionUtils.FIELD_ADDITIONAL_SCRIPT): [additionalCode, ""],
(CloneIssue.FIELD_COPY_COMMENTS) : true,
(CloneIssue.FIELD_TARGET_PROJECT) : "DEST",
(CloneIssue.FIELD_LINK_TYPE) : clonesId + " inward",
(CloneIssue.FIELD_SELECTED_FIELDS) : null, //clone all the fields
] as Map<String, Object>

def errorCollection = cloneIssue.doValidate(inputs, false)
if (errorCollection.hasAnyErrors()) {
log.warn("Couldn't clone issue: ${errorCollection}")
}
else {
cloneIssue.doScript(inputs)
}

Adaptavist ScriptRunner for JIRA 5.4.12

Yes, that did the trick! Thank you!

How did you know that, btw? Is there documentation that would have told me that the interface seems to have changed at some point?

Joshua Yamdogo _ 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.
Jul 13, 2018 • edited

Hi Damon,

That's a good question. I took a quick look at our documentation and I don't see an example of CloneIssue being used manually, so I don't think you would have known about any changes. I can see how that would be frustrating!

The problem here, in my opinion, is that running CloneIssue manually is something we don't particularly want everyone to do, so it's not likely to end up in the documentation. It can be difficult to use and often creates more problems for users than it solves, since the built-in clone script is often "good enough." Only in niche cases do we recommend doing it, such as in your situation.

In any case, if you run into a problem like this again, I'd suggest submitting a support request through our Service Desk portal here: https://marketplace.atlassian.com/apps/6820/scriptrunner-for-jira?hosting=server&tab=support

Regards,

Josh

Thanks again.

Hi @Joshua Yamdogo _ Adaptavist , 

 

is there a full documentation out there in the internetz about the possible map values of the CloneIssue params? 

 

CloneIssue.FIELD_COPY_COMMENTS
CloneIssue.*WHAT CAN I DO HERE ¯\_(ツ)_/¯ *

 

 

Thanks for your time, 

cheers

slothy  

Like # people like this

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events