title: Google Script append Element to HTML Document
body: <p>I want to load data from my Google Script into my HTML Document and send it by email.  When I run the code below, I get the error <code>ReferenceError: "document" is not defined.</code>.</p>
  
  <p>I don't understand the cause of the error, or, how to fix it.</p>
  
  <p>My GS Script:</p>
  
  <pre><code>function sendEmail(){
    //Email Template
    var emailTemp = HtmlService.createTemplateFromFile("template"); // Access to the HTML document
    // Tab Stichprobe
    var stichprobe = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Stichprobe");
    var stichprobecapital = stichprobe.getRange("A2:L"+stichprobe.getLastRow()).getDisplayValues(); // Array AssetName
    var software = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Software");
    var softwarecapital = software.getRange("A2:E"+software.getLastRow()).getDisplayValues();
    var test=[];
    var stichprobelen = stichprobe.getRange("A2:A"+stichprobe.getLastRow()).getDisplayValues().length; 
    var softwarelen = software.getRange("A2:A"+software.getLastRow()).getDisplayValues().length; 
    var softwareindex = [];
  
    //Config
    var config = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Config");
    var subject = config.getRange("B1:B1").getValue();
    var counter = config.getRange("B5:B5").getValue();
    var subject = config.getRange("B1:B1").getValue();
    var replyto = config.getRange("B3:B3").getValue();
    var name = config.getRange("B2:B2").getValue();
    var error = config.getRange("B6:B6").getValue();
    var cc = config.getRange("B4:B4").getValue();
  
    for (var a = 0; a&lt;stichprobelen; a++){
      for (var i = 0; i&lt;softwarelen; i++){
        if (softwarecapital[i][0] == stichprobecapital[a][0]){
          softwareindex.push(i);
        }
      }
      var softindexlen = softwareindex.length;
      for(var b = 0; b &lt; softindexlen; b++) {
        var node =  document.createElement("LI"); 
        var textnode =  document.createTextNode(softwarecapital[0][1]);
        node.appendChild(textnode);
        document.getElementById("liste").appendChild(node); 
  
      }
      var htmlMessage = emailTemp.evaluate().getContent();
      GmailApp.sendEmail(stichprobecapital[a][2], subject, error,{name:name, htmlBody: htmlMessage, replyTo: replyto, cc: cc});
    }
  }
  </code></pre>
  
  <p>My HTML Script:</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
    &lt;head&gt;
      &lt;base target="_top"&gt;
    &lt;/head&gt;
    &lt;body&gt;
      &lt;ul id="liste"&gt;
      &lt;/ul&gt;
    &lt;/body&gt;
  &lt;/html&gt;
  
  
  
  </code></pre>
  
  <p>Greetings</p>