I can't seem to get a form-triggered script to run right. To be precise, it runs, and I can do some things, but I can't access the form data that is supposed to be sent to the event handler function.
I've got a very simple script triggered by a Google Sheet form:
function OnFormSubmit(e)
{
try {
var timeStamp = e.namedValues["Timestamp"][0];
MailApp.sendEmail(emailAddress, "SCRIPT ENTRY", timeStamp);
} catch (x) {
var message = x.toString() + "\n[" + Utilities.jsonStringify(e) + "]\n"
MailApp.sendEmail(emailAddress, "SCRIPT ERROR", message);
}
}
I've also got a very simple form with just one item. I've got the trigger set up. The form runs and adds a line to the spreadsheet. I get email, so the script is triggering. However I get the SCRIPT ERROR email. The message is:
TypeError: Cannot read property "Timestamp" from undefined.
[{"response":"FormResponse","authMode":"FULL"}]
The "Timestamp" does indeed exist in the Form Response sheet (as I believe it always will; Timestamp is an automatic entry).
It seems that OnFormSubmit() is not being passed the parameter I think it's supposed to get passed. But all the examples I see work like this.
Any help?