Google Script send form values by email, error: Cannot read property "Timestamp" from undefined/Cannot read property "0" from undefined. I add two options with two bugs, the script receive the info from exel file. the code is below:
function sendFormByEmail(e) {
var Subject = "Subject";
var Email = "email";
var Key = "keynumber";
var Editors = 0;
var extraColumns = 8;
if (useEditors) {
var editors = DocsList.getFileById(Key).getEditors();
if (editors) {
var notify = editors.join(',');
} else var notify = Email;
} else {
var notify = Email;
}
var s = SpreadsheetApp.getActive().getSheetByName("Form Responses 1");
if (extraColumns) {
var headers = s.getRange(1, 1, 1, extraColumns).getValues()[0];
} else var headers = s.getRange(1, 1, 1, s.getLastColumn()).getValues()[0];
var message = "";
for (var i in headers) {
//First case:
// message += headers[i] + ' = '+ s.namedValues[headers[i]].toString() + "\n\n";
//var i is "Timestamp"
//TypeError: Cannot read property "Timestamp" from undefined.
//Second case:
message += headers[i] + ' = ' + s.values[i].toString() + '\n\n';
//TypeError: Cannot read property "0" from undefined.
}
MailApp.sendEmail(notify, Subject, message);
}
I have the following two errors in first and second types: 1)TypeError: Cannot read property "Timestamp" from undefined 2)TypeError: Cannot read property "0" from undefined. What is my error?