I'm looking for a way to iterate through a spreadsheet of responses using Google Script (basically same thing as JavaScript). It worked okay, but the problem is this code keeps sending emails for data that has already been sent in an email. I know very little JavaScript, but I think it would make sense to delete the previous row and only iterate through one row. Here is the code so far:
function autoEmail() {
var sheet = SpreadsheetApp.getActiveSheet();
var startRow = 2;
var numRows = 2;
var dataRange = sheet.getRange(startRow, 1, numRows, 7)
var data = dataRange.getValues();
for (i in data) {
var column = data[i];
var emailAddress = "OMITTED FOR PRIVACY";
var message = column[3] + ", who is a " + column[4] + " Scout, wants to have a " + column[6] + " on " + column[5] + ". You can contact him at " + column[1] + ". This is an automated email sent by OMITTED FOR PRIVACY.";
var subject = column[3] + " Wants To Rank Up!";
MailApp.sendEmail(emailAddress, subject, message);
}
}
Any suggestions?