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.
I tried https://community.atlassian.com/t5/Adaptavist-questions/I-want-to-clone-comments-with-Scriptrunner-for-Jira-Cloud/qaq-p/720819
https://community.atlassian.com/t5/Jira-questions/Scriptrunner-When-I-clone-issue-I-wanna-include-comments-to/qaq-p/610237
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 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.
Is there a way to clone issue comments in Jira Next Gen (cloud)?
If you want a custom script I can share my code
Hi,
But is it possible to deep clone it with Jira Automation?
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.
I really need this, so I would love to get your custom script!
i need this script as well
package com.adaptavist.sr.cloud.samples.eventsimport org.apache.log4j.Loggerimport groovy.json.JsonSlurperdef log = Logger.getLogger("com.acme.workflows")//Wybieramy pole z project pickerdef customFieldName = 'customfield_10036'//wyciagamy poladef fields = get("/rest/api/2/issue/${issue.key}?fields") .header('Content-Type', 'application/json') .asObject(Map).body.fieldsdef projectKeyFromField = fields.customfield_10036.keydef selectedFields = fields.customfield_10037.value as Listdef summary = fields.summarydef components = fields.components.iddef reporter = fields.reporterdef labels = fields.labelsdef assignee = fields.assigneedef comment = fields.commentdef attachment = fields.attachmentdef subtasks = fields.subtasksdef originalKey = issue.keylog.warn(originalKey)//def projectKey = projectKeyFromFielddef projectId = get("/rest/api/2/project/${projectKeyFromField}").asObject(Map).body.idlog.warn(projectId)// Wyszukujemy ID typu taskadef taskType = get("/rest/api/2/issuetype/project?projectId=${projectId}").asObject(List).body.find { it['name'] == 'Zadanie' }['id']log.warn(taskType)//Tworzymy zgłoszeniedef 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.keylog.warn(postedIssue)def createdIssueKey = postedIssue as Stringlog.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 zalacznikiif(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).bodydef 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 subtaskadef 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ą przenoszoneif(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 issuedef soucrceIssueKey = "TS-2"// Specify the target issuedef targetIssueKey = "TS-3"// Spcecify the link type to usedef linkType = "Duplicate"// Create the issue link between both issuesdef 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 correctlyif (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}"}
It looks like you're new here. Sign in or register to get started.