As a newcomer to Google Script and JavaScript, I'm on a mission to email a list of file names extracted from a spreadsheet. The names reside in a column within my sheet, and after defining a variable called "newfiles" to cherry-pick only the necessary values, things seemed promising.
function sendUpdate()
{
//initialize variables
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("finishedfiles");
var range = sheet.getDataRange().getValues();
for (n = 0; n < range.length; n++)
{
var newfiles = range[n][1];
}
The snag arises when the script dispatches an email for each value in the range.
var startRow = 2;
for (var i = 0; i < range.length; i++)
if (startRow + i , 5 != '')
{
MailApp.sendEmail
{to: "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="cba6ae8bca6aaa2a7e5a8a4a6">[email protected]</a>",
subject: "list of files",
htmlBody: "Here's your list:<br>" + newfiles +
"<br>This message was sent automatically."});
}
To solve this issue, I need to amalgamate the values in my variable into a single text string that can be embedded in my message so as to send just one email.
Although it feels like a novice question, I'm struggling to crack the code.