Hi All,
I am I am using jira cloud and script runner for jira.
When I tried to clone from post function with script runner Comments were not getting cloned.
but no luck.
Thanks in advance
Hi Pooja,
I can confirm that you have linked to above will not work inside of ScriptRunner for Jira Cloud is due to the fact the code you have provided is fro ScriptRunner for Jira Server and this will not work as Atlassian only provide a rest API in Jira Cloud and do not provide a Java API in the cloud like they do in Jira Server.
You can see more detailed information on the differences between the cloud and server versions inside of our documentation page located here.
I can also confirm that it is not possible to copy comments using the Clone Issue post function inside of Jira Cloud due to the restricted nature of Jira Cloud which means that it is not possible to copy the issue and its comments at the same time.
This means that you will need to use a seperate approach such as writing a custom script to copy the issue which can use the Get Comments and Add Comment API's to copy the comments between issues.
If this response has answered your question can you please mark it as accepted so that other users can see it is correct when searching for similar answers.
Regards,
Kristian
If you want a custom script I can share my code :)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I really need this, so I would love to get your custom script!
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.
package com.adaptavist.sr.cloud.samples.events
import org.apache.log4j.Logger
import groovy.json.JsonSlurper
def log = Logger.getLogger("com.acme.workflows")
//Wybieramy pole z project picker
def customFieldName = 'customfield_10036'
//wyciagamy pola
def fields = get("/rest/api/2/issue/${issue.key}?fields")
.header('Content-Type', 'application/json')
.asObject(Map).body.fields
def projectKeyFromField = fields.customfield_10036.key
def selectedFields = fields.customfield_10037.value as List
def summary = fields.summary
def components = fields.components.id
def reporter = fields.reporter
def labels = fields.labels
def assignee = fields.assignee
def comment = fields.comment
def attachment = fields.attachment
def subtasks = fields.subtasks
def originalKey = issue.key
log.warn(originalKey)
//def projectKey = projectKeyFromField
def projectId = get("/rest/api/2/project/${projectKeyFromField}").asObject(Map).body.id
log.warn(projectId)
// Wyszukujemy ID typu taska
def taskType = get("/rest/api/2/issuetype/project?projectId=${projectId}").asObject(List).body.find { it['name'] == 'Zadanie' }['id']
log.warn(taskType)
//Tworzymy zgłoszenie
def postedIssue = post('/rest/api/2/issue')
.header('Content-Type', 'application/json')
.body(
[
fields: [
summary : summary,
description: "Test",
labels : labels,
reporter : reporter,
assignee : assignee,
components : [{
id : components}
],
project : [
key: projectKeyFromField
],
issuetype : [
id: taskType
]
]
])
.asObject(Map).body.key
log.warn(postedIssue)
def createdIssueKey = postedIssue as String
log.warn(fields.comment.comments.created)
if(selectedFields.contains("Komentarze")){
log.warn(fields.comment.comments.body.size())
for(int i = 0; i < fields.comment.comments.body.size(); i++){
post('/rest/api/2/issue/' + createdIssueKey + '/comment')
.header('Content-Type', 'application/json')
.body([
body : fields.comment.comments.body[i],
created:fields.comment.comments.created[i],
author: [
displayName: comment.comments.author.displayName[i]
]
])
.asObject(Map)
}
}
//wrzucamy zalaczniki
if(selectedFields.contains("Załączniki")){
for(int i = 0; i < attachment.size(); i++ ){
def attId = attachment.id[i]
def att = Unirest.get('/rest/api/2/attachment/' + attId).asObject(Map).body
def downloadUrl = attachment.content[i]
def readFileResp = Unirest.get(downloadUrl).asBinary()
log.warn(downloadUrl)
def response = Unirest.post('/rest/api/2/issue/' + createdIssueKey + '/attachments')
.header("Accept", "application/json")
.header("X-Atlassian-Token", "nocheck")
.field("file", readFileResp.body, att.title.toString())
.asObject(Map)
}
}
//id subtaska
def subTaskType = get("/rest/api/2/issuetype/project?projectId=${projectId}").asObject(List).body.find { it['name'] == 'Podzadanie' }['id']
log.warn(subTaskType)
//sprawdzmay czy są subtaski, jeśli tak - są przenoszone
if(subtasks != null){
for(int i = 0; i< subtasks.size(); i++){
post('/rest/api/2/issue')
.header('Content-Type', 'application/json')
.body(
[
fields: [
summary : subtasks.fields.summary[i],
description: subtasks.fields.description[i],
reporter : reporter,
assignee : assignee,
parent : [
key : postedIssue
],
project : [
key: projectKeyFromField
],
issuetype : [
id: subTaskType
]
]
])
.asObject(Map).body.key
}
}
//Linkowanie zgloszen
// Specify the source issue
def soucrceIssueKey = "TS-2"
// Specify the target issue
def targetIssueKey = "TS-3"
// Spcecify the link type to use
def linkType = "Duplicate"
// Create the issue link between both issues
def link = post('/rest/api/3/issueLink')
.header('Content-Type', 'application/json')
.body([
type: [ name: linkType ],
outwardIssue: [ key: originalKey ], // This is the issue that the link 'starts' at.
inwardIssue: [ key: createdIssueKey ] // This is the issue that the link 'finises' at.
])
.asString()
// validate that the issue link created correctly
// Validate the issue updated correctly
if (link.status == 201) {
return "Success - The issues with the key of ${soucrceIssueKey} and ${targetIssueKey} have been linked with the ${linkType} link type."
} else {
return "${link.status}: ${link.body}"
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Lukasz
I owe you a big bottle of "Zoladkowa Gorzka" (or any other vodka :) )
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Here to help, just check if it's work, I've created it some time ago :)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I have also run into this same issue. We are currently cloning an issue as Workflow Post Function. I am very new to all of this. Where does this script go?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
My code is for cloud, works as a postfunction
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Is there a way to clone issue comments in Jira Next Gen (cloud)?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
If you don't want to write a custom script you can try our cloud app Deep Clone for Jira. With that app you can clone comments and other advanced content.
It's also possible to bulk clone thousands of issues and move them in one go.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
But is it possible to deep clone it with Jira Automation?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
If you want to trigger a clone from post-function, you can work with the Deep Clone workflow post-function.
If you want to trigger a clone with Jira Automation, but don't want to change the status, you can work with a looping transition and a Deep Clone post-function.
If you want to trigger an automation from a Deep Clone you can create an incoming webhook.
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.