using Apps Scripts to send summary email of info from Google Tables

29 views
Skip to first unread message

Katie Olaskiewicz

unread,
Aug 29, 2023, 1:42:17 PM8/29/23
to Google Apps Script Community
Hi all,

Been trying to get this to work for a while now, this is my first time using Apps Scripts! I want to set up a bot to execute an Apps Script, but I think I'm having trouble with the code - though, to be honest, it could be something I'm doing wrong in Tables and I'd have no idea!

When I debug, I'm getting a reference error that Tables is not defined, but I thought Tables.get was a function/action, not a variable I need to define? I'm very confused! Looks like I'm going to have trouble with the last few lines, too, like it will tell me Utilities and Date are also undefined....

function sendEmailWithTableData() {
var tableId = "w9XTffV05Bo0b2rip6EkBM";
var recipients = ["k.olas...@gmail.com"];
var startDate = "2023-08-29";
var startTime = "18:00";

var table = Tables.get(tableId);

var data = table.getData();

var filteredData = data.filter(function(row) {
return row[0] === "current";
});

var body = "<table>";
for (var i = 0; i < filteredData.length; i++) {
body += "<tr>";
for (var j = 0; j < filteredData[i].length; j++) {
body += "<td>" + filteredData[i][j] + "</td>";
}
body += "</tr>";
}
body += "</table>";

var mail = Utilities.createEmail(recipients);
mail.setSubject("Table Data");
mail.setBody(body);
mail.setSendAt(new Date(startDate, startTime));
mail.send();
}
Reply all
Reply to author
Forward
0 new messages