-1

Anyone aware of what the problem is here? It has worked multiple times, even with

const htmlForEmail = htmlTemplate.evaluate().getContent(); and now it seems to throw back an error:

The error: Error

SyntaxError: Unexpected token '<' electrical @ electrical.gs:24 I am on runtime version- runtimeVersion- "V8"

My google app script code (html code is below it):

 function electrical() {

    const ss = SpreadsheetApp.getActiveSpreadsheet ();
    
    const ws = ss.getSheetByName("Bid Request");

    const h1 = ws.getRange("G4").getValue();
    const headers = ws.getRange("G5:H5").getValues();
    const project = headers [0][0];
    const response = headers [0][1];

    const lr =ws.getLastRow();
    const tableRangeValues = ws.getRange(6,2,lr-6,2).getDisplayValues();

    const htmlTemplate = HtmlService.createTemplateFromFile("email");
    htmlTemplate.h1 = h1;
    htmlTemplate.headers = headers;
    htmlTemplate.project = project;
    htmlTemplate.response = response;
    htmlTemplate.tableRangeValues = tableRangeValues;

    const htmlForEmail = htmlTemplate.evaluate().getContent();

    console.log(htmlForEmail);

    GmailApp.sendEmail(
    "example@gmail.com",
    "Bid Request",
    "Please",
    {htmlBody: htmlForEmail}
 
   );

  
   }

html:

<!DOCTYPE html>
<html>
<head>
<base target="_top">
</head>
<body>
<div>
 <div>
 </div>
 <div>
    
  <h1><?= h1 ?></h1>
  <div></div>
  <table>

  <thead>
  <tr>
  <th><?= project ?></th><th><?= response></th>
  </tr>
  </thead>

  <tbody>

  <? tableRangeValues.forEach(r => { ?>
  <tr>
  <td><?= r[0] ?></td><td><?= r[1] ?></td>
  </tr>
  <?}) ?>

  </tbody>

      
  </div>
  </div>

  </body>
  </html> 

For some reason the html is not letting me show that I have header/body tags and html defined document tag, but I do!

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
GudCoder
  • 1
  • 2

1 Answers1

2

There's a typo in your html code

<thead>
  <tr>
  <th><?= project ?></th><th><?= response></th>
  </tr>
  </thead>

It should be like this

<thead>
  <tr>
  <th><?= project ?></th><th><?= response ?></th>
  </tr>
  </thead>

Hope that fix your problem

  • Yeah, in my case I had these snippets in my html `a.push(">")` and `a.push("<%"+s+"?>")`. Just to clarify that they were not my edits to make a template, they just came with the original html that gulp created for me. I think the Google parser was erroneously picking them app as part of the template. I had to change the question marks with something else and then it worked :) – Edgar Manukyan Oct 14 '22 at 18:36