onit
onit

Reputation: 2372

html file and the script not resulting correct output (Google Sheets)

I've been trying to get this one to work, but without success...

The output I got in my email is pure text, exactly like the html is written in the file. There is more to it, but I'm sure the flw is within the part of scripts shared.

This is the script and the html file:

function emailUpdatedStatus() {
  var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Atividades");
  var history = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Updates');
  var historyData = history.getRange(5,1,history.getLastRow(),5).getValues();
  var startRow = 9;  // First row of data to process
  var numRows = sheet.getLastRow();   // Number of rows to process
  var dataRange = sheet.getRange(startRow, 1, numRows, 24);
  
  //Variables for the Email Formatted Table
  const reportTitle = "Histórico da Atividade";
  const subHeader = history.getRange("B3").getValue();
  const headers = history.getRange("A4:E4").getValues();
  const lastTbUpdate = headers[0][0];
  const histTbNo = headers[0][1];
  const histTbStatus = headers[0][2];
  const histTbObs = headers[0][3];
  const histTbUser = headers[0][4];
  const histLastRow = history.getLastRow();
  const tableRngValues = history.getRange(5, 1, histLastRow-5,5).getValues();
  
  const htmlTemplate = HtmlService.createTemplateFromFile('email');
  htmlTemplate.reportTitle = reportTitle;
  htmlTemplate.subHeader = subHeader;
  htmlTemplate.lastTbUpdate = lastTbUpdate;
  htmlTemplate.histTbStatus = histTbStatus;
  htmlTemplate.histTbNo = histTbNo;
  htmlTemplate.histTbObs = histTbObs;
  htmlTemplate.histTbUser = histTbUser;
  htmlTemplate.tableRngValues = tableRngValues;
  
  const htmlForEmail = htmlTemplate.getContent();
  }
<!DOCTYPE html>
<html>
    <head>
        <base target=_top>
        </head>
        <body>
            <div>
                <div></div>
                <div>
                    <h1>
                        <?= reportTitle ?>
                    </h1>
                    <div>
                        <? subHeader ?>
                    </div>
                    <div></div>
                    <table>
                        <thead>
                            <tr>
                                <td>
                                    <?= lastTbUpdate ?>
                                </td>
                                <td>
                                    <?= histTbStatus ?>
                                </td>
                                <td>
                                    <?= histTbObs ?>
                                </td>
                                <td>
                                    <?= histTbUser ?>
                                </td>
                            </tr>
                        </thead>
                        <tbody>
                            <tr>
                                <td>
                                    <?=  ?>
                                </td>
                                <td>
                                    <?=  ?>
                                </td>
                                <td>
                                    <?=  ?>
                                </td>
                                <td>
                                    <?=  ?>
                                </td>
                            </tr>
                        </tbody>
                    </table>
                </div>
            </div>
        </body>
    </html>

Any light as to where the flaw lies is appreciated.

Upvotes: 1

Views: 84

Answers (1)

Wicket
Wicket

Reputation: 38200

Replace

const htmlForEmail = htmlTemplate.getContent();

by

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

Upvotes: 1

Related Questions