1

I am a bit stuck and can't figure why I'm getting this syntax error.

I have created a script that creates an email with the content I input into a google sheet that takes a template from an HTML file I made and it works beautifully.

However, now that I want to move the sheet to a more communal sheet for other users to operate I just get a syntax error. I've copied the sheet to the accurate cells in the new sheet and I've copied both the .gs and .html code line for line and updated the Sheet ID and sheet name and I have no idea how to fix it.

I'm suspecting that this has something to do with my.html not matching but I've doublechecked this and even changed the file names just to be sure but can't seem to troubleshoot the problem.

Hoping for some input from anyone could shed some light on my predicament.

Here is the full code:

function EODemail2() {

  const ss=SpreadsheetApp.openById('xxxxxxxxxxxxxxxxxxxx');
  const sh=ss.getSheetByName('Sheet 1'); 
  const lr= sh.getLastRow()  
  const emailAddress = sh.getRange(2,4).getValue();
  const dearAll = sh.getRange(2,2).getDisplayValue();
  const message = sh.getRange(3,2).getDisplayValue();
  const subscriptions= sh.getRange(4,2).getValue();
  const subscriptionsNumbers=sh.getRange(6,3,2,4).getValues();
  const subsComments=sh.getRange(6,2).getValues();
  const operations= sh.getRange(8,2).getValue();
  const weLognumbers=sh.getRange(9,2,6,4).getValues();
  const operationsreport= sh.getRange(16,2).getValue();
  const customerService=sh.getRange(18,2).getValue();
  const csdata = sh.getRange(19,2,5,3).getDisplayValues();
  const csSubs= sh.getRange(25,2).getValue();
  const replacementRequests= sh.getRange(26,2).getValue();
  const replacmentDataTable=sh.getRange(27,3,8,9).getValues(); 
  const lastComents = sh.getRange(37,2).getDisplayValue();
  const endParagraph = sh.getRange(39,2).getDisplayValue();
  const name = sh.getRange(41,2).getDisplayValue();
  const htmlTemplate = HtmlService.createTemplateFromFile('email');
  htmlTemplate.dearAll = dearAll;
  htmlTemplate.message = message;
  htmlTemplate.subscriptions = subscriptions;
  htmlTemplate.subscriptionsNumbers = subscriptionsNumbers;
  htmlTemplate.subsComments = subsComments;
  htmlTemplate.operations = operations;
  htmlTemplate.operationsreport = operationsreport;
  htmlTemplate.customerService = customerService;
  htmlTemplate.weLognumbers = weLognumbers;
  htmlTemplate.csdata = csdata;
  htmlTemplate.csSubs = csSubs;
  htmlTemplate.replacementRequests = replacementRequests;
  htmlTemplate.replacmentDataTable = replacmentDataTable;
  htmlTemplate.lastComents = lastComents;
  htmlTemplate.endParagraph = endParagraph;
  htmlTemplate.name = name;
  const htmlForEmail=htmlTemplate.evaluate().getContent();

  console.log(htmlForEmail);


  const date = Utilities.formatDate(new Date(), "GMT+0", "dd/MM/yyyy")
  const emailBody = "Hi "+date+"\n \n"+customerService;
  const subject= "EOD for "+date
 Utilities.sleep(10000)
  Logger.log(emailAddress)
  GmailApp.sendEmail(emailAddress, subject, dearAll,{ htmlBody: htmlForEmail } );
}

Here is my .HTML template I know it's simple but it's just a report so please excuse its simplicity and excuse how I've structured my HTML code, I'm not too experienced with this.

<!DOCTYPE html>
<html>
  <head>
    <base target="_top">
  </head>
  <body>
      <div>
        <div>
        </div>
          <p><?=dearAll1?></p> 
          <p><?=message1?></p> 
          <div style= "font-weight:bold"; ><?=subscriptions1?></div> 

<br>
   <table style="border-spacing:0px; border-collapse: collapse">

     <tbody>
   <?subscriptionsNumbers1.forEach(r=>{?>
       <tr>
        <th style= "font-weight:normal; text-align:left; padding:7px; border:1px solid black;"><?= r[0] ?></th><th style= "font-weight:normal; text-align:left; padding:7px; border:1px solid black;"><?= r[1] ?></th>
      </tr>
      <?})?>
      </tbody>
      </table>

      <p><?=subsComments1?><p/> 
          <br>     

      <div> </div>
       <p style= "font-weight:bold";> <?=operations?> </p>


        <table style="border-spacing:0px; border-collapse: collapse">
     <tbody>
   <?weLognumbers.forEach(r=>{?>
       <tr>
        <th style= "font-weight:normal; text-align:left; padding:7px; border:1px solid black;"><?= r[0] ?></th><th style= "font-weight:normal; text-align:left; padding:7px; border:1px solid black;"><?= r[1] ?></th><th style= "font-weight:normal; text-align:left; padding:7px; border:1px solid black;"><?= r[2] ?></th>
      </tr>
      <?})?>
      </tbody>
      </table>

      <div> </div>
       <p> <?=operationsreport?> </p>

       <div> </div>
       <p style= "font-weight:bold";> <?=customerService?></p>
       <table style="border-spacing:0px; border-collapse: collapse">
      <tbody>
        <?csdata.forEach(n=>{?>
       <tr>
        <th style= "font-weight:normal; text-align:left; padding:7px; border:1px solid black;"><?= n[0] ?></th><th style= "font-weight:normal; border:1px solid black; padding:7px;"><?= n[1] ?></th>
      </tr>
      <?})?>

      </tbody>
      </table>
      <div> </div>
     <p style= "font-weight:bold";> <?=csSubs?></p>
     <p> <?=replacementRequests?></p>

      <table style="border-spacing:0px; border-collapse: collapse">
      <tbody>
        <?replacmentDataTable.forEach(n=>{?>
       <tr>
        <th style= "font-weight:normal; border:1px solid black; padding:5px;"><?= n[0] ?></th><th style= "text-align:left; font-weight:normal; border:1px solid black; padding:5px;"><?= n[1] ?></th><th style= "font-weight:normal; border:1px solid black; padding:5px;"><?= n[2] ?></th><th style= "font-weight:normal; border:1px solid black; padding:5px;"><?= n[3] ?></th><th style= "font-weight:normal; border:1px solid black; padding:5px;"><?= n[4] ?></th><th style= "font-weight:normal; border:1px solid black; padding:5px;"><?= n[5] ?></th><th style= "font-weight:normal; border:1px solid black; padding:5px;"><?= n[6] ?></th>
      </tr>
      <?})?>
      </tbody>
      </table>

      <p><?=lastComents?><p/>
<br>
      <p><?=endParagraph?></p> 

      <p><?=name?></p> 


</div>
  </body>
</html> 
  • 1
    Don't know exactly, but does [this](https://stackoverflow.com/questions/61897189/script-error-on-internal-function-when-calling-another-function-in-a-library/61902071#61902071) answer your question? HTML and code seem fine, but the runtime of your script (check appsscript.json) might be mixed up - is it V8? – Oleg Valter is with Ukraine Jun 05 '20 at 21:11
  • 1
    @Cooper - I think this *is* the exact error message - I used to deal with this problem when I started a lot - the message in regards to what happened during the template evaluation is not that clear (although I may be wrong, I distinctly recall this exact form). – Oleg Valter is with Ukraine Jun 05 '20 at 21:24
  • 1
    You could create all of your html server side and load with after the dom loads with window.onload or $(function it's a little slower but a heck of a lot easier to write. – Cooper Jun 05 '20 at 21:25
  • `const emailBody = "Hi "+date+"\n \n"+customerService;` there's not \n in html but I don't think this line is even being used. So that's probably not the problem. – Cooper Jun 05 '20 at 21:48
  • Where are you getting the syntax error? – Jescanellas Jun 08 '20 at 08:36
  • 1
    @OlegValter Sorry for taking some time to get back to this. I'm only getting the chance to tackle this problem again now. You were completely right I was running V8 on my old script which I was not aware of and my new sheet was running the old engine. Thank you for pointing me in the right by checking appsscript.json. although a pop-up does appear staring me in the face the whole time inform me that I'm running V8. – Benson Batty Jun 13 '20 at 10:39
  • 1
    No problem (it is a very common issue, but the error message does not help at all) - I marked the question as duplicate: [Script Error on internal function when calling another function in a library](https://stackoverflow.com/questions/61897189/script-error-on-internal-function-when-calling-another-function-in-a-library) – Oleg Valter is with Ukraine Jun 13 '20 at 10:43

1 Answers1

0

I've managed to figure out the problem why I was getting the on the htmlTemplate.evaluate().getContent(); line. Shoutout to Oleg in the comments section for pointing me in the right direction.

The problem was that I was running the new V8 engine on my old script and when I pasted the whole code into the desired sheet I was running the old engine which was not compatible with the old engine google apps script was using.

The simple answer was I upgraded to V8 and the whole script worked perfectly.