0

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)]
    })}
  • 1
    Normally people get that type of error when they try to run triggered functions from the editor with supplying the event object. Since the event object is not there the e.namedValues can not be there either. – Cooper Mar 25 '21 at 04:59
  • Does this answer your question? [How can I test a trigger function in GAS?](https://stackoverflow.com/questions/16089041/how-can-i-test-a-trigger-function-in-gas) – Iamblichus Mar 26 '21 at 08:29

0 Answers0