I am trying to send an automatic email (text used from a google doc template) to all form responders that includes an attachment. and it keeps returning: Error TypeError: Cannot read property 'namedValues' of undefined onFormSubmit @ Code.gs:14 I'm not sure what where I'm going wrong
My script belw:
var EMAIL_TEMPLATE_DOC_URL =
'https://docs.google.com/document/d/1u89xsr09fWZ3kMmfQg2kagvZ_GiYQl3P4QkX6wPWTzw/edit?usp=sharing';
var EMAIL_SUBJECT = 'Membership Application';
var formvehicle = DriveApp.getFileById('1Q2Y7ZfUv4bCmdSmmLDQyvT0MCffp3T3P');
function installTrigger() {
ScriptApp.newTrigger('onFormSubmit')
.forSpreadsheet(SpreadsheetApp.getActive())
.onFormSubmit()
.create();
}
function onFormSubmit(e) {
var responses = e.namedValues;
var email = responses['Email Address'][0].trim();
var name = responses.Name[0].trim();
MailApp.sendEmail({
to: email,
subject: EMAIL_SUBJECT,
htmlBody: createEmailBody(name, topics),
attachments: [formvehicle.getAs(MimeType.PDF)]
})}