Need help with Sending Table onto email of body

233 views
Skip to first unread message

Ramon Corrales

unread,
Apr 15, 2021, 2:12:06 PM4/15/21
to Google Apps Script Community
Team

I am building code to pull a table from my google sheet and then add the table to the body of an email, but I am getting an error.

ERROR:  SyntaxError: Illegal return statement  at sendEmail(Code:34:37)  const htmlForEmail = htmlTemplate.evaluate().getContent();     

I'm working on my html file..... but my current concern is this error.

Can someone provide some guidance?


here is my code:

Function sendEmail() {
 
  const ss  = SpreadsheetApp.getActiveSpreadsheet();
  const ws = ss.getSheetByName("AgentData"); //  Tab Name
 
  const hmonth = ws.getRange("A7").getValue(); // Month of QA
  const hhello = ws.getRange("A9").getValue();  //  Hello and Name of Agent
  const headers = ws.getRange("A11:B11").getValues(); // Header  Topic & Results
  const topics = headers[0][0];
  const results = headers[0][1];
   
   
   
  const lr = ws.getLastRow();

  const tableRangeValues = ws.getRange(12,1,lr-12,2).getDisplayValues();  // Range of Data that is dynamic
   
  const textfooter = ws.getRange(12,1,lr-12,2).getValues();  
  const footer = ws.getRange("A21").getDisplayValue(); //  Positive Feedback statement
  const subfooter = ws.getRange("A22").getDisplayValue();  // Continuation of the Positive Feedback statement
 

  const htmlTemplate = HtmlService.createTemplateFromFile("EmailTable");  // HTML file
  htmlTemplate.hmonth = hmonth;
  htmlTemplate.hhello = hhello;
  htmlTemplate.topics = topics;
  htmlTemplate.results = results;
  htmlTemplate.footer = footer;
  htmlTemplate.subfooter = subfooter;
  htmlTemplate.tableRangeValues = tableRangeValues;

 
 
  const htmlForEmail = htmlTemplate.evaluate().getContent();     
 
  console.log(htmlForEmail);
 
  var spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
  var individualSheet = spreadheet.getActiveSheet();
 
  var recipient = individualSheet.getRange(3,2).getValue();
  var ccemail =  individualSheet.getRange(3,7).getValue();
 

MailApp.sendEmail({
  to: toEmail,
  cc: ccEmail,
  subject: "This is a Test..Amigo",
  htmlBody: htmlForEmail
});
   
    }
   
   

Ramon Corrales

Workforce Manager

Experience Center & Learning Space Services

University Technology Office

Arizona State University

Mail Code: 6504

1150 E University Dr. Suite 115

Tempe, AZ 85281

p: 855-278-5080 

email: ramon.c...@asu.edu

web: uto.asu.edu

 linkedin 


ASU #1 in the U.S. for innovation

 



Ramon Corrales

unread,
Apr 15, 2021, 2:21:43 PM4/15/21
to Google Apps Script Community
Team,  sorry forgot to attach this table.

This is an example of the table I am trying to add to the body of an email



Ramon Corrales

Workforce Manager

Experience Center & Learning Space Services

University Technology Office

Arizona State University

Mail Code: 6504

1150 E University Dr. Suite 115

Tempe, AZ 85281

p: 855-278-5080 

email: ramon.c...@asu.edu

web: uto.asu.edu

 linkedin 


ASU #1 in the U.S. for innovation

 





From: google-apps-sc...@googlegroups.com <google-apps-sc...@googlegroups.com> on behalf of Ramon Corrales <Ramon.C...@asu.edu>
Sent: Thursday, April 15, 2021 11:11 AM
To: Google Apps Script Community <google-apps-sc...@googlegroups.com>
Subject: [Apps-Script] Need help with Sending Table onto email of body
 
--
You received this message because you are subscribed to the Google Groups "Google Apps Script Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-script-c...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-script-community/BYAPR06MB4886FD9319BA6DAE2067CF5F814D9%40BYAPR06MB4886.namprd06.prod.outlook.com.

Alan Wells

unread,
Apr 15, 2021, 3:33:22 PM4/15/21
to Google Apps Script Community
We need to see the scriptlet code in the html file: EmailTable
I think that the error is coming when evaluating (running the code in) the EmailTable file.

Ramon Corrales

unread,
Apr 15, 2021, 4:03:27 PM4/15/21
to Google Apps Script Community
Ok.. Here it is

Thanks for your help.



<!DOCTYPE html>
<html>
  <head>
    <base target="_top">
    </head>
  table, th, td {
  border: 0px solid black;
  font-size:15px;
}

th, thead {
  background-color: lightblue;
}

</style>  
  </head>
  <body>
    <div>
    <Hmonth><? Hmonth ?></Hmonth>
    <div><? Hhello ?></div>
    <div></div>
      <table>
     
        <thead>
        <tr>
          <th><?= topics ?></th><th><?= results ?></th>
        </tr>
        </thead>
        <tbody >
       
          <? tablerangeValues.forEach(r => {?>
             
              <tr>
                <td><?= r[0] ?></td><td><?= r[1] ?></td>
              </tr>
           <?})?>
           
           
          <td><?= footer ?></td><td><?= subfooter ?></td>
          </tr>
          <?})?>
         
        </tbody>
       <tfooter>
       <tr>
       <td><?= footer ?></td><td><?= subfooter ?></td>
      </tr>
      </table>
    </div>
  </body>
</html>




Ramon Corrales

Workforce Manager

Experience Center & Learning Space Services

University Technology Office

Arizona State University

Mail Code: 6504

1150 E University Dr. Suite 115

Tempe, AZ 85281

p: 855-278-5080 

email: ramon.c...@asu.edu

web: uto.asu.edu

 linkedin 


ASU #1 in the U.S. for innovation

 





From: google-apps-sc...@googlegroups.com <google-apps-sc...@googlegroups.com> on behalf of Alan Wells <aj.a...@gmail.com>
Sent: Thursday, April 15, 2021 12:33 PM

To: Google Apps Script Community <google-apps-sc...@googlegroups.com>
Subject: [Apps-Script] Re: Need help with Sending Table onto email of body
 

Ramon Corrales

unread,
Apr 15, 2021, 6:24:35 PM4/15/21
to Google Apps Script Community
I found my error.  

Alan, you were right,  it was in html code....

That hint, made me review the html code.... and fixed a few of he code, now it works as I wanted to..


thants

Ramon Corrales

Workforce Manager

Experience Center & Learning Space Services

University Technology Office

Arizona State University

Mail Code: 6504

1150 E University Dr. Suite 115

Tempe, AZ 85281

p: 855-278-5080 

email: ramon.c...@asu.edu

web: uto.asu.edu

 linkedin 


ASU #1 in the U.S. for innovation

 



Sent: Thursday, April 15, 2021 1:03 PM

To: Google Apps Script Community <google-apps-sc...@googlegroups.com>
Subject: Re: [Apps-Script] Re: Need help with Sending Table onto email of body
 

Alan Wells

unread,
Apr 15, 2021, 7:10:19 PM4/15/21
to Google Apps Script Community
Glad you found it.

On Thursday, April 15, 2021 at 6:24:35 PM UTC-4 jcor...@asu.edu wrote:
I found my error.  

Alan, you were right,  it was in html code....

That hint, made me review the html code.... and fixed a few of he code, now it works as I wanted to..


thants

Ramon Corrales

Workforce Manager

Experience Center & Learning Space Services

University Technology Office

Arizona State University

Mail Code: 6504

1150 E University Dr. Suite 115

Tempe, AZ 85281

p: 855-278-5080 

email: ramon.c...@asu.edu

web: uto.asu.edu

 linkedin 


ASU #1 in the U.S. for innovation

 



Reply all
Reply to author
Forward
0 new messages