1

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?

codemon
  • 1,456
  • 1
  • 14
  • 26
  • 1
    Possible duplicate of [How can I test a trigger function in GAS?](https://stackoverflow.com/questions/16089041/how-can-i-test-a-trigger-function-in-gas) – Rubén Jan 31 '18 at 16:24

1 Answers1

2

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.)

  • I know that just running it in the script editor would not create the trigger, I just mentioned in passing that I tried it both from the script editor and from form submit - which I mentioned was correctly populating the spreadheet. However your suggestion of using `values` instead of `response` was the winner. Thanks. – codemon Oct 27 '17 at 23:23