1

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.

8
  • 1
    so what is the error that it shows? You have there some <?= ?> empty tags, this can be a problem. also you have <? subHeader ?> there should be <?= subHeader ?> right? Commented Sep 2, 2020 at 21:54
  • Hi @IvanSatsiuk! Just corrected it to <?= subHeader ?>. I guess that the problem has to do with const htmlForEmail = htmlTemplate.getContent(); I've read that there has to be evaluate(), but when I add it, I get an error: SyntaxError: Unexpected token ';' Commented Sep 3, 2020 at 0:54
  • 1
    Can you show us how you send the email? Commented Sep 3, 2020 at 3:12
  • This is how I'm sending the email, @ThumChoonTat MailApp.sendEmail({ name: "NAME", to: emailAddress, subject: subject, htmlBody: message }); Commented Sep 3, 2020 at 12:23
  • 1
    Is the message coming from htmlForEmail variable? Commented Sep 4, 2020 at 2:55

1 Answer 1

1

Replace

const htmlForEmail = htmlTemplate.getContent();

by

const htmlOutput = htmlTemplate.evaluate();
const htmlForEmail = htmlOutput.getContent();
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.