I'm trying to set up a script to send an email everytime a new row is added into my google sheets worksheet. The worksheet is currently connected to my google forms.
However, I can't get this code to save as the error shows SyntaxError: Invalid or unexpected token (line 11, file "Email.gs"
.
I've been trying several times but can't figure out what is wrong. I would really appreciate some help with this script, Thank you.
function sendEmail() {
//setup function
var ActiveSheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
if (ActiveSheet.getName() == 'FORM' ) {
var StartRow = 2;
var RowRange = ActiveSheet.getLastRow() – StartRow + 1;
var WholeRange = ActiveSheet.getRange(StartRow,1,RowRange,17);
var AllValues = WholeRange.getValues();
var message = "";
//iterate loop
for (i in AllValues) {
//set current row
var CurrentRow = AllValues[i];
//set HTML template for information
message +=
"<p><b>Entered: </b>" + CurrentRow[1] + "</p>" +
"<p><b>Timestamp: </b>" + CurrentRow[2] + "</p>" +
"<p><b>Name: </b>" + CurrentRow[3] + "</p>" +
"<p><b>ID No.: </b>" + CurrentRow[4] + "</p>" +
"<p><b>Contact: </b>" + CurrentRow[5] + "</p>" +
"<p><b>Address: </b>" + CurrentRow[6] + "</p>" +
"<p><b>Temperature: </b>" + CurrentRow[7] + "</p>" +
"<p><b>Check In Date: </b>" + CurrentRow[8] + "</p>" +
"<p><b>Room Number: </b>" + CurrentRow[9] + "</p>" +
"<p><b>Bank Details: </b>" + CurrentRow[10] + "</p>" +
"<p><b>Symptoms: </b>" + CurrentRow[11] + "</p>" +
"<p><b>Contact: </b>" + CurrentRow[12] + "</p>" +
"<p><b>Agree to SOP: </b>" + CurrentRow[13] + "</p>" +
"<p><b>Declaration: </b>" + CurrentRow[14] + "</p>" +
"<p><b>Full Name: </b>" + CurrentRow[15] + "</p>" +
"</p><br><br>";
}
}//For loop close
//define who to send emails to
var SendTo = "myemail@email.com";
//set subject line
var Subject = "New Form";
//send the actual email if message is not empty
if (message) {
MailApp.sendEmail({
to: SendTo,
subject: Subject,
htmlBody: message,
});
}//if message
}//if sheetName Review
}//End Func