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,559,016
Community Members
 
Community Events
184
Community Groups

How do I obtain the new issue's key when using Scriptrunner's 'Clone Issue' example script

I'm attempting to use ScriptRunner to build a REST endpoint to clone issues (as it seems this is not supported in the API as is) so that items can be cloned using the API. 

I have found the example script (https://library.adaptavist.com/entity/basics-clone-issue) will clone the issue, but doesn't return the details of the new item that have been created.

Any ideas how I can get the key of the new item would be appreciated, as I hope then to return that back in the response to the calling script for further use.

1 answer

1 vote
Ram Kumar Aravindakshan _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 17, 2023 • edited

Hi @Richard Lucas

For your requirement, you can use the working sample code below:-

import com.adaptavist.hapi.jira.issues.Issues

final def originalIssueKey = 'MOCK-1'
final def amountField = 'Amount'
final def sampleTextField = 'Sample Text Field'

def originalIssue = Issues.getByKey(originalIssueKey)

def clonedIssue = Issues.create(originalIssue.projectObject.key, originalIssue.issueType.name) {
setSummary(originalIssue.summary)
setDescription(originalIssue.description)
setReporter(originalIssue.reporter)
setCustomFieldValue(amountField, originalIssue.getCustomFieldValue(amountField).toString())
setCustomFieldValue(sampleTextField, originalIssue.getCustomFieldValue(sampleTextField).toString())

if (originalIssue.assignee) {
setAssignee(originalIssue.assignee)
}

if (originalIssue.components.size() > 0) {
def components = originalIssue.components.collect { it.name}.toArray() as String[]
setComponents(components)
}
}

if (originalIssue.comments) {
originalIssue.comments.each {
clonedIssue.addComment(it.body)
}
}

log.warn "====== Cloned Issue Key ${clonedIssue.key}"

Please note that the working sample code above is not 100% exact to your environment. Hence, you will need to make the required modifications.

At the very bottom of the code, you will see there is a log.warn added, this will print out the Cloned Issue's key.

Please also ensure that you upgrade your ScriptRunner plugin to the latest release, i.e. 8.2.1, so you can use the HAPI feature as shown in the sample above to simplify the code.

I hope this helps to answer your question. :-)

Thank you and Kind regards,

Ram

Ram Kumar Aravindakshan _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 24, 2023

Hi @Richard Lucas

Does the code provide the answer to your question?

If yes, please accept the solution.

Thank you and Kind regards,

Ram

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events