Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Deleted user
0 / 0 points
Next:
badges earned

Your Points Tracker
Challenges
Leaderboard
  • Global
  • Feed

Badge for your thoughts?

You're enrolled in our new beta rewards program. Join our group to get the inside scoop and share your feedback.

Join group
Recognition
Give the gift of kudos
You have 0 kudos available to give
Who do you want to recognize?
Why do you want to recognize them?
Kudos
Great job appreciating your peers!
Check back soon to give more kudos.

Past Kudos Given
No kudos given
You haven't given any kudos yet. Share the love above and you'll see it here.

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

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

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?

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
Community showcase
Published in Marketplace Apps & Integrations

Staying organized with Jira: best practices for a better project management

Project managers know this problem: A “mountain of work” lays in front of you, and you don’t know how and where to tackle them. Different to-dos lie ahead, but just one task after the other can be ha...

248 views 2 1
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you