0

Trying to produce a Comment Log in a Google sheet based on a Google Doc.

I applied the script as suggested by NaziA in this link. And I activated the DriveAPI service.

function listComments() {
  // Change docId into your document's ID
  // See below on how to
  var docId = '1fzYPRldd16KjsZ6OEtzgBIeGO8q5tDbxaAcqvzrJ8Us'; 
  var comments = Drive.Comments.list(docId);
  var hList = [], cList = [];

  // Get list of comments
  if (comments.items && comments.items.length > 0) {
    for (var i = 0; i < comments.items.length; i++) {
      var comment = comments.items[i]; 
      // add comment and highlight to array's first element 
      hList.unshift([comment.context.value]);
      cList.unshift([comment.content]);
    }
    // Set values to A and B
    var sheet = SpreadsheetApp.getActiveSheet();
    sheet.getRange("A1:A" + hList.length).setValues(hList);
    sheet.getRange("B1:B" + cList.length).setValues(cList);
  }
}

I used the suggested code verbatim with one change. I replaced the DocumentID with the ID from the new Google sheet I was using as a target. After I approved the permission, it executed without errors but did not write any values to the Google Sheet. I had a demo Google Doc as a source with few comments.

Screenshot of Comment Doc

Any suggestions?

  • In order to correctly replicate your issue of `it executed without errors but did not write any values to the Google Sheet.`, can you provide your sample Document? Because when I tested your script, no issue occurs. I couldn't replicate your situation. I apologize for this. – Tanaike Dec 07 '21 at 23:17
  • The above screenshot shows the document. Here is the link https://docs.google.com/document/d/1T1ZedlE7s8qevgzUqNG_kpsurA-BtyJ5-EHnB2vihbc/edit?usp=sharing – Carl Springer Dec 08 '21 at 18:35
  • Thank you for replying. When I saw your sample Document, no comments are included. I thought that this is the reason for your issue. So please add some comments and test it again. I think that when a comment is added, your script works. – Tanaike Dec 08 '21 at 23:25
  • Thanks for the feedback. That is weird because the "Test Comments" doc at the above link has 4 comments in it. So you really cannot see them? – Carl Springer Dec 08 '21 at 23:53
  • Thank you for replying. Unfortunately, I cannot see the comments. This might be the reason of your issue. For example, when you created new Document and add the comments, what result will you obtain? – Tanaike Dec 09 '21 at 00:07

0 Answers0