3

Hello is possible twhen copying a Google Doc document to copy also the comments in the "copy doc."Because I've tried this with the TEMPLATE_DOC_ID which has many comments and I don't find the comments in the "copy".I am missing something?It's another method? Thanks!

//Make a copy of the template file
        var documentId = DriveApp.getFileById(TEMPLATE_DOC_ID).makeCopy().getId();
Tanaike
  • 181,128
  • 11
  • 97
  • 165
ana maria
  • 353
  • 1
  • 4
  • 22

1 Answers1

8

Unfortunately, the Google Docs copied by makeCopy() don't include the comments. So the comments and replies are required to be inserted to the copied file, after the file was copied. In order to implement this, please enable Drive API at Advanced Google Services and API console.

Enable Drive API v2 at Advanced Google Services

  • On script editor
    • Resources -> Advanced Google Services
    • Turn on Drive API v2

Enable Drive API at API console

About Drive API, in your environment, this might have already been enabled.

  • On script editor
    • Resources -> Cloud Platform project
    • View API console
    • At Getting started, click Enable APIs and get credentials like keys.
    • At left side, click Library.
    • At Search for APIs & services, input "Drive". And click Drive API.
    • Click Enable button.
    • If API has already been enabled, please don't turn off.

Sample script :

var documentId = DriveApp.getFileById(TEMPLATE_DOC_ID).makeCopy().getId();

// Added script
var commentList = Drive.Comments.list(TEMPLATE_DOC_ID);
commentList.items.forEach(function(item) {
  var replies = item.replies;
  delete item.replies;
  var commentId = Drive.Comments.insert(item, documentId).commentId;
  replies.forEach(function(reply) {
    Drive.Replies.insert(reply, documentId, commentId).replyId;
  });
});

Note :

  • Unfortunately, the create time and modified time couldn't updated. So the date becomes the created date.

References :

If this was not what you want, I'm sorry.

Tanaike
  • 181,128
  • 11
  • 97
  • 165
  • @Tanaike unfortunately it doesn't work for Slides documents, I get **"Anchor is missing required property root.r"** error. Any idea how to insert comment into Slides? – Kos Oct 04 '18 at 13:24
  • @Kos Thank you for the information. In the current stage, I cannot answer about the solution immediately. I'm really sorry for my poor skill. – Tanaike Oct 05 '18 at 13:27
  • @Kos Although I had tried several ways, I couldn't find about the structure of anchor for Google Slides and also cannot find the formal document. I'm really sorry for my poor skill. If you have information, can I ask you about the structure for Google Slides? – Tanaike Oct 06 '18 at 23:09
  • @Tanaike I've come to this format, it creates comment in Slides doc, but it doesn't become bound to 10th slide: `"anchor": "{\"r\":\"2\",\"a\":[{\"page\":{\"p\": 10, \"mp\": 13}}]}`. So probably Google doesn't want allow us add comments to Google Slides – Kos Oct 07 '18 at 10:11
  • @Kos Yes. Although in my environment, also I had used ``page`` and confirmed that a comment was added, it cannot find on the Slides. I thought of about [``Custom schemas``](https://developers.google.com/drive/api/v3/manage-comments#custom_schemas). But I couldn't find the detail structure. I wonder if the values retrieved by Drive API cannot be used for adding. – Tanaike Oct 07 '18 at 22:49