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!