You're on your way to the next level! Join the Kudos program to earn points and save your progress.
Level 1: Seed
25 / 150 points
Next: Root
1 badge earned
Challenges come and go, but your rewards stay with you. Do more to earn more!
What goes around comes around! Share the love by gifting kudos to your peers.
Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!
Join now to unlock these features and more
The Atlassian Community can help you and your team get more value out of Atlassian products and practices.
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.
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
Does the code provide the answer to your question?
If yes, please accept the solution.
Thank you and Kind regards,
Ram
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.