javascript - Trouble with Google MailApp html option -
i having trouble setting script iterate through google spreadsheet , email employees lines contain reports them.
in tests email address , subject lines being emailed depending on try email either blank or says "[object object]".
i viewing emails gmail site in chrome.
the html code not have variables yet. still working on getting email correctly , try working in scriplets build table report.
code.gs
function changename() { var ss = spreadsheetapp.getactivespreadsheet(); var sha = ss.getsheets()[0]; // report download var shb = ss.getsheets()[1]; // names & email address var alrow = sha.getlastrow(); var blrow = shb.getlastrow(); var data = sha.getrange(1, 1, alrow, 14).getvalues(); // array of employees reports var employees = shb.getrange(1, 1, 2, 2).getvalues(); // list of employees [i][0] , email address [i][1] in scorecard data for(i=0;i<employees.length;i++){ var html = htmlservice.createtemplatefromfile('index').evaluate(); mailapp.sendemail(employees[i][1], employees[i][0] + ' scorecards test', {htmlbody: html.getcontent()}); logger.log(html.getcontent()); } }
index.html
<body> <p1>test 5062</p1> <table> <tr> <td>test cell 1</td> <td>test cell 2</td> <td>test cell 3</td> </tr> </table> </body>
when view log, shows html file.
what doing wrong?
how following modification?
from :
function changename() { var ss = spreadsheetapp.getactivespreadsheet(); var sha = ss.getsheets()[0]; // report download var shb = ss.getsheets()[1]; // names & email address var alrow = sha.getlastrow(); var blrow = shb.getlastrow(); var data = sha.getrange(1, 1, alrow, 14).getvalues(); // array of employees reports var employees = shb.getrange(1, 1, 2, 2).getvalues(); // list of employees [i][0] , email address [i][1] in scorecard data for(i=0;i<employees.length;i++){ var html = htmlservice.createtemplatefromfile('index').evaluate(); mailapp.sendemail(employees[i][1], employees[i][0] + ' scorecards test', {htmlbody: html.getcontent()}); logger.log(html.getcontent()); } }
to :
function changename() { var ss = spreadsheetapp.getactivespreadsheet(); var sha = ss.getsheets()[0]; // report download var shb = ss.getsheets()[1]; // names & email address var alrow = sha.getlastrow(); var blrow = shb.getlastrow(); var data = sha.getrange(1, 1, alrow, 14).getvalues(); // array of employees reports var employees = shb.getrange(1, 1, 2, 2).getvalues(); // list of employees [i][0] , email address [i][1] in scorecard data for(i=0;i<employees.length;i++){ var html = htmlservice.createtemplatefromfile('index').evaluate(); mailapp.sendemail({ to: employees[i][1], subject: employees[i][0] + ' scorecards test', htmlbody: html.getcontent() }); logger.log(html.getcontent()); } }
if didn't work, i'm sorry.
Comments
Post a Comment