I'm sending an email from sheets using the following code, but I have an issue...
I can't move to the next iteration where the sent column = "Yes" ie: only want to include rows where the sent column = ""
Thanks in advance for your assistance.
function sendEmail() {
//setup function
var ActiveSheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
var StartRow = 2;
var RowRange = ActiveSheet.getLastRow() - StartRow + 1;
var WholeRange = ActiveSheet.getRange(StartRow,1,RowRange,11);
var AllValues = WholeRange.getValues();
var message = "";
//iterate loop
for (i in AllValues) {
//set current row
var CurrentRow = AllValues[i];
//define column to check if sent
const EmailSent = CurrentRow[11];
//if row has been sent, then continue to next iteration
if (EmailSent == "Yes")
continue;
//set HTML template for information
message +=
"<p><b>Date of Works: </b>" + CurrentRow[0] + "</p>" +
"<p><b>Customer: </b>" + CurrentRow[1] + "</p>" +
"<p><b>Project No: </b>" + CurrentRow[2] + "</p>" +
"<p><b>Project: </b>" + CurrentRow[3] + "</p>" +
"<p><b>Location: </b>" + CurrentRow[4] + "</p>" +
"<p><b>Site Contact: </b>" + CurrentRow[5] + "</p>" +
"<p><b>Starting Point: </b>" + CurrentRow[6] + "</p>" +
"<p><b>Start Time: </b>" + CurrentRow[7] + "</p>" +
"<p><b>Truck Size: </b>" + CurrentRow[8] + "</p><br><br>";
//set the row to look at
var setRow = parseInt(i) + StartRow;
//mark row once Sent
ActiveSheet.getRange(setRow, 11).setValue("Yes");
}
//define who to send email to
var SendTo = "[email protected]"
//set subject line
var Subject = "#6 Test - 2 - Selected Rows";
//send the actual email
MailApp.sendEmail({
to: SendTo,
cc: "",
subject: Subject,
htmlBody: message,
});
}