I was using the below script to send an auto emails through Sheet "Reference" whenever any data is filled by Google form into sheet "Data".
I do not know how to make a loop to do this task that whenever any data is updated on sheet "Data" from Google form then automatically an email has been sent to the mail available in "Reference" sheet Col"G" after sending the email to that particular entity, code should mention in "Reference" sheet Col"N" as Mail sent.
"Reference" sheet Col"O" is Notification Text "Reference" sheet Col"M" is subject "Reference" sheet Col"G" is such email where code will send above mentioned data
Code should not sent email again on those ID's in "Reference" sheet Col"N" where on "Email Sent" i mentioned.
function sendEmails2() {
var sheet = SpreadsheetApp.getActiveSpreadsheet();
var sheetname= sheet.getSheetByName("Reference");
var startRow = 2; // First row of data to process
var numRows = sheetname.getLastRow("Reference"); // Number of rows to process
// Fetch the range of cells A2:B3
var dataRange = sheetname.getRange(startRow, 1, numRows, 15);
// Fetch values for each row in the Range.
var data = dataRange.getValues();
for (var i = 0; i < data.length; ++i) {
var row = data[i];
var emailAddress = row[6]; // First column
var message = row[13]; // Second column
var emailSent = row[14]; // Third column
if (emailSent !== EMAIL_SENT && row[12] == "Mail Send" && row[6] != "") { // Prevents sending duplicates
var subject = row[11];
MailApp.sendEmail(emailAddress, subject, message);
sheetname.getRange(startRow + i, 15).setValue(EMAIL_SENT);
// Make sure the cell is updated right away in case the script is interrupted
SpreadsheetApp.flush();
}
}
}
Any help would be highly appreciated