Brian
Brian

Reputation: 4344

Trouble accessing Footnotes class Google Scripts

I'm trying to write up a simple script which will take a footnote added to a Google Document and copy it into an endnotes section. So, the user would use footnotes as normal and then run the script to shift them to the end of the document when they're finished.

I've got a script which returns an array containing [Footnote, Footnote] from my test doc with two included, but I cannot figure out how to convert the object to a string.

function getNotes() {
  var doc = DocumentApp.getActiveDocument().getFootnotes();
  Logger.log(doc);
}

I've pored over the documentation, and I'm really confused because I can't seem to find the getFootnoteContents method mentioned in the Footnotes class. Any direction would be really appreciated.

Upvotes: 0

Views: 143

Answers (1)

Spencer Easton
Spencer Easton

Reputation: 5782

getFootnotes() return an array of footnote objects. You will need to iterate over them to access each one.

function getFootnotes(){
  var doc = DocumentApp.openById('...');
  var footnotes = doc.getFootnotes();
  for(var i in footnotes ){
    Logger.log(footnotes[i].getFootnoteContents().getText());    
  }    
}

Upvotes: 1

Related Questions