Google Apps脚本onFormSubmit(e)“e未定义”?

时间:2017-10-27 22:22:56

标签: javascript google-apps-script

我正在尝试获取表单提交以将新问题推送到github。这是代码,我从一份评论者得到的代码中得到了这些代码:

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);
}

然而,这不起作用,当我在脚本编辑器中运行脚本时或当我提交表单响应时,我得到TypeError: Cannot call method "getItemResponses" of undefined. (line 7, file "Code")(顺便设置触发器以使用存储的数据在表单上运行在电子表格中,我验证了它正在填充。

我做错了什么?为什么e未定义?

1 个答案:

答案 0 :(得分:0)

如果在脚本编辑器中运行它,当然e未定义;它的价值来自哪里?它包含什么?事件对象由触发器填充。

电子表格触发器FormSubmit没有response字段,因此e.response未定义。

具有response字段的表单触发器FormSubmit。要创建它,请转到表单的脚本编辑器,而不是电子表格。 (或者,如果您想使用已有的电子表格触发器,只需确保访问它具有的属性,例如values。)