google-apps-scriptfootnotes

GETFOOTNOTES() and ALERT: How can I verify i f students append a footnote?


I want to verify on google docs if students added a footnote. My scripts doesn't run.

script:

  function addNote () {
  const menuMessage = DocumentApp.getUi();
  const doc = DocumentApp.getActiveDocument();
  const notePiedPage = doc.getFootnotes();

  if(notePiedPage == DocumentApp.ElementType.FOOTNOTE){
    menuMessage.alert('Génial, le 3e mot de passe est BISCOTO');
  } 
  else {
    menuMessage.alert('Erreur...');
  }
}

Solution

  • This looks incorrect:

    const notePiedPage = doc.getFootnotes();
    if(notePiedPage == DocumentApp.ElementType.FOOTNOTE){
      menuMessage.alert('Génial, le 3e mot de passe est BISCOTO');
    } 
    

    because getFootnotes() returns an array

    Try something like this:

    function HowManyFootNotes() {
      const ui = DocumentApp.getUi();
      const doc = DocumentApp.getActiveDocument();
      const fA = doc.getFootnotes();
      if (fA.length > 0) {
        ui.alert(`This document has ${fA.length} footnotes`)
      }
    }
    

    Class Footnote