0

I am writing a google apps script that places the paragraphs of one document into a dictionary, then inserts them into a set of other documents based on certain criteria. The paragraphs are extracted like so:

var totalElements = doc.getNumChildren();

for( var j = 0; j < totalElements; ++j ) {
  var element = doc.getChild(j).copy();
  var type = element.getType();

  // logic to add element to dictionary
}

Later, once the location a paragraph should be inserted is found, it is inserted via the insertParagraph() function:

body.insertParagraph(paragraphIndex, element); 

This works fine, except for the fact that some paragraphs have comments attached to them that need to be copied along with them, and this method does not keep comments attached to their elements. Is there any way to implement this? Thanks for any help!

  • 1
    Welcome to StackOverflow. Try using the advanced Drive service https://stackoverflow.com/questions/50913184/access-google-docs-comments-from-google-app-scripts – Anton Dementiev Mar 01 '20 at 20:11
  • did the other Stack Overflow's post shared by @AntonDementiev helped you? – alberto vielma Mar 03 '20 at 12:29
  • Thanks for the link, Anton! This is a good starting place--I'm now trying to figure out how best to get the comment's position in the doc (and, later on, set its anchor when I add it to the new doc). In particular, I can't make sense of how the anchor property of the comments returned by Drive.Comments.list, a string that tends to look something like "kix.tbn76917wgqg," corresponds to the region json objects described in the documentation here: https://developers.google.com/drive/api/v3/manage-comments. Is there any way to decode the anchor string into a position in the document? – Jordan Brownstein Mar 04 '20 at 02:43
  • @JordanBrownstein, please open a new question. One post must only contain one issue to answer. If you have more doubts, feel free to create a new question. – alberto vielma Mar 04 '20 at 10:02

0 Answers0