codemon
codemon

Reputation: 1594

Google Apps Script onFormSubmit(e) "e is undefined"?

I am trying to get a form submit to push a new issue to github. Here is the code, which I got from a gist which commenters seem to have been able to get working :

var ghToken = "MY_TOKEN";



function onFormSubmit(e) {
  Logger.log(e)
var result = e.response.getItemResponses();

var testResult = result[1].getResponse();
var describeIssues = result[2].getResponse();
var issueScreenshot = result[3].getResponse();
var iosMail = result[4].getResponse();
var iosGmail = result[5].getResponse();
var iosOutlook = result[6].getResponse();  
var androidGmail = result[7].getResponse();
var androidOutlook = result[8].getResponse();
var androidYahoo = result[9].getResponse();


var body = "## Status \n" +
"![warning]" + testResult +"\n" +
describeIssues +"\n" +
"______________________________________________________________________________________________________\n" +
issueScreenshot +"\n" +
"______________________________________________________________________________________________________\n" +
"## Test Results\n" +
"#### iOS\n" +
"| Mail | Outlook | Gmail\n" +
"| ------------- |:-------------:| :--------------:|\n" +
"| ![ios mail]"+iosMail+" | "+iosOutlook+" | "+iosGmail+"\n" +
"| **Interactive** | **Static** | **Static**\n"+
"| Interactive module off-center | Working - 2-column | Working 1-column\n"+
"#### Android = Samsung s8+\n" +
"| Gmail | Outlook | Yahoo! Mail\n" +
"| ------------- |:-------------:| :--------------:|\n" +
"| ![ios mail]"+iandroidGmail+" | "+androidOutlook+" | "+androidYahoo+"\n" +
"| **Interactive** | **Static** | **Static**\n"+
"| Interactive module off-center | Working - 2-column | Working 1-column\n";

  var payload = {
    "title": "Jon testing",
    "body": body
  };

  var options = {
    "method": "POST",
    "contentType": "application/json",
    "payload": JSON.stringify(payload)
  };

  var response = UrlFetchApp.fetch("https://api.github.com/repos/me/myRepo/issues?access_token="+ghToken, options);
}

This doesn't work however, when I run the script in the script editor or when I submit the form response I get TypeError: Cannot call method "getItemResponses" of undefined. (line 7, file "Code") (by the way the triggers are set correctly to run on form submit using data stored in spreadheet, which I verified is being populated).

What am I doing wrong? Why is e undefined?

Upvotes: 1

Views: 3009

Answers (1)

user6655984
user6655984

Reputation:

If you run it in the script editor, of course e is undefined; where would its value come from? What would it contain? Event objects are populated by a trigger.

A Spreadsheet trigger FormSubmit does not have a response field, so e.response is undefined.

It's the Form trigger FormSubmit that has response field. To create it, go to the Script Editor of the form, not of the spreadsheet. (Or, if you want to use the Spreadsheet trigger you already have, just make sure you access the properties that it has, such as values.)

Upvotes: 2

Related Questions