Google 脚本中 onSubmit 的事件对象为空 [英] Event object of onSubmit is empty in Google script
问题描述
我有一个链接到 Google 表格的 Google 表单.在那个电子表格中,我有这样的代码
I have a Google form linked to a Google sheet. In that spreadsheet I have code that have this
function onSubmit(e){
Logger.log(e)
Logger.log("Call onSubmit")
}
触发器设置如下
Project: Spreadsheet's scritp
Deployment:Head
Event:From spreadsheet - On form submit
Function:onSubmit
所以每当我提交表单时,日志都会显示
So whenever I submit the form, the log shows
[object Object]
Call onSubmit
表格有很多问题,不是空表格.当我阅读文档时,事件对象似乎有很多信息.我的设置有问题吗?我已经求助于阅读数据表中的回复,但这并不理想.必须手动调用和/或定义太多东西.
The form has many questions, not an empty form. As I read the documentation, it seems like the event object has many information. Is there something wrong with my setup? I have resorted to read responses in the data sheets but that's not ideal. Too many things have to call and/or defined manually.
推荐答案
记录器有问题,不建议直接依赖您在调试器中看到的内容.
The logger is buggy and it is not recommended to rely directly on what you see in the debugger.
总是使用
console
类而不是Logger
总是 JSON.stringify()
你要记录的任何东西:
Always JSON.stringify()
anything that you're going to log:
console.log(JSON.stringify(e));
最后一个应该可以解决您的问题.[object Object]
是在对象上调用 toString()
的结果,因为记录器无法直接显示对象.
The last one should fix your problem. [object Object]
is the result of calling toString()
on a object, as the logger is incapable to displaying a object directly.
const obj = {a:1};
console.log(obj.toString());//[object Object]
console.log(JSON.stringify(obj));//'{"a":1}'
这篇关于Google 脚本中 onSubmit 的事件对象为空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!