user2188317
user2188317

Reputation: 81

Trigger in Google Form submit does not work properly

I have a script that is running when a form is submitted. The script does not work when I use a function with the e parameter such as the code below. I get a message returned: ReferenceError: 'e' is not defined. Any idea why?

function submitFormFunc(e) {
  var items = e.response.getResponses();
  var responses={};
  for(var i = 0; i< items.length; i++) {
   responses[items[i].getItem().getTitle()]=items[i].getResponse();
  }

  var responseTable = [];
  var responseIndex = ["Timestamp","ID","question 1","question 2"];
  responseTable.push(e.response.getTimestamp().toString());
  responseTable.push(e.response.getId());
  responseTable.push(responses["question 1"]);
  responseTable.push(responses["question 2"]);
  responseTable.push(FormApp.getActiveForm().getResponse(e.response.getId()).getEditResponseUrl());
  SpreadsheetApp.openById("your spreadsheetId").appendRow(responseTable);
}

Upvotes: 0

Views: 445

Answers (1)

Mogsdad
Mogsdad

Reputation: 45750

You are receiving that error because the event object, e, isn't defined when you've called submitFormFunc(e). This is typical when you are debugging, and have invoked a parameterized function from the editor/debugger.

For your testing, simulate the event using the technique from How can I test a trigger function in GAS?

Upvotes: 1

Related Questions