Reputation: 1
I have this code to send Google Form responses to email.
function sendFormByEmail(e) {
Logger.log("e: " + e);
var email = "[email protected]";
var s = SpreadsheetApp.getActiveSheet();
var headers = s.getRange(1,1,1,s.getLastColumn()).getValues()[0];
var message = "";
var subject = "New Hire Form Submission: ";
for(var i in headers)
message += headers[i] + ': '+ e.namedValues[headers[i]].toString() + "\n\n";
// Insert variables from the spreadsheet into the subject.
// This creates an email subject like "New Hire: Jane Doe - starts 4/23/2013"
subject += e.namedValues[headers[2]].toString() + " - starts " + e.namedValues[headers[15]].toString();
// Send the email
MailApp.sendEmail(email, subject, message);
}
This is tied to the spreadsheet not the form and e is returning undefined. I saw someone else have this issue and disabling the new Chrome V8 worked for them but is not working for me.
Upvotes: 0
Views: 161
Reputation: 713
By the time the function is called, the data is already in the spreadsheet, so you could just read the last now
var row = SpreadsheetApp.getActiveSheet().getLastRow();
var columns = s.getLastColumn()
var range = s.getRange(row, 1, 1, columns).getValues();
Upvotes: 1