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.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.