I'm having an issue with my Google Script. It actually works as-is but the problem is that after the form is submitted and someone submits a new form the first submitted form will no longer send an email because it's looking for the LastRow. I'm having difficulties getting this to work correctly... Can someone assist?
The column highlighted in yellow, after it has been filled out by a vendor the 5th column to the right (green) should also fill in "Sent" letting the user know an email has been sent to the person who created the form.
Here's a picture of the form to hopefully get a better idea http://i57.tinypic.com/34tej4w.png
function sendNotification() {
var doc = SpreadsheetApp.getActiveSpreadsheet();
var sheet = doc.getSheets()[0];
var startRow = sheet.getLastRow();
var dataRange = sheet.getRange(startRow, 1, 1, 21) ;
var data = dataRange.getValues();
var row;
for (i in data) {
row = data[i];
var EMAIL_SENT = 'Sent';
var emailSent = row[19]; // Third column
if (emailSent != EMAIL_SENT) { // Prevents sending duplicates
//Define Notification Details
var subject = "Row 12 has been edited!";
var body =
'<html><body><b><u>Product Check</u></b>'
+ '<br><b>Time: </b>'
+ row[0]
+ '<br><b>Email requested: </b>'
+ row[1]
+ '<br><b>Request date: </b>'
+ row[2]
+ '<br><b>ISBN: </b>'
+ row[4]
+ '<br><b>Product Title: </b>'
+ row[7]
+ '<br><b>Supplier Name: </b>'
+ row[8]
+ '<br><b>PO Number: </b>'
+ row[10]
+ '<br><b>Comments: </b>'
+ row[12]
+ '<br>View the spreadsheet here: <a href="#"><b>Click here</b></a> </html></body>';
if (row[13] != '' && row[0] != '' && row[18] == '') {
var recipients = row[1];
var subject = "Column 'N' was edited!";
sheet.getRange(startRow, 19, 1, 1).setValue(EMAIL_SENT) && sheet.getRange(startRow, 19, 1, 1).setBackgroundColor("#00ff00");
SpreadsheetApp.flush();
MailApp.sendEmail({
to: recipients,
subject: subject,
htmlBody: body});
}