为什么Google Forms不会在formSubmit上返回用户响应? [英] Why Google Forms does not return user response on formSubmit?
问题描述
我创建了一个示例Google表单,并定义了如下函数:
I have created a sample google form, and defined a function like below:
function onFormSubmit(e) {
Logger.log('Inside function');
Logger.log('Emailing data row ->');
var itemResponses = e.getItemResponses();
var email = itemResponses[0].getResponse();
Logger.log(itemResponses);
}
在编辑->当前项目的触发器
我添加了要在表单提交上调用的函数:
In Edit-> Current project's triggers
I have added the function to be called on form submit:
在我的执行
部分,我看到以下错误:
In My Executions
section I see the error below:
TypeError:无法调用未定义的方法 getItemResponses。在onSubmit(Code:7)
TypeError: Cannot call method "getItemResponses" of undefined. at onSubmit(Code:7)
为什么会这样?我应该如何捕获表单字段?我的代码是否有问题,或有某些权限?
Why is it like that? How should I capture form fields? Is there something wrong with my code, or some permissions?
推荐答案
Google表单
仅在新创建的表单上发生:
It seems that there was a bug in Google Forms
which is being happened only on newly created forms:
- Google forms script on form submit - event does not have FormResponse
建议2种解决方法:
1)在代码中的某个位置包含对FormApp的调用,即使在评论中。
例如:
1) Include a call to FormApp somewhere in the code, even in a comment. For example:
// FormApp.getActiveForm();
// FormApp.getActiveForm();
2)添加范围并按照以下
说明添加到您的Apps脚本清单文件中:
2) Add the scope to your Apps Script manifest file, as per these instructions:
https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes
要添加的范围是 https://www.googleapis.com/auth/forms
完成这两个选项之一后,请重新授权
脚本。您可以通过在脚本编辑器中运行任何功能来执行此操作。
Once you've completed either of those two options, re-authorize your script. You can do this be running any function in the script editor.
这篇关于为什么Google Forms不会在formSubmit上返回用户响应?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!