google-apps-script - GAS onFormSubmit 触发器在第一个 console.log 之后返回
问题描述
问题:对于某些用户,我只能看到第一个 logToConsole()。然后似乎该函数返回而没有抛出错误或其他任何东西。
到目前为止我已经检查/尝试过的内容:
- 保存在共享云端硬盘与我的云端硬盘中的 Google 表单
- 创建新表格
function onSubmitInst(event) {
logToConsole('onSubmitInst start'); // Is logged
var form, docProps, valueStatus, formLimits, realFormValueCell, mailFormStatus, formTitle;
try {
docProps = PropertiesService.getDocumentProperties();
} catch (error) {
logToConsole('onSubmitInst property error'); // Is NOT logged
return;
}
form = event.source;
formTitle = form.getTitle();
mailFormStatus = docProps.getProperty('mailForm');
formLimits = docProps.getProperty('formLimits');
formLimits = formLimits ? JSON.parse(formLimits) : {};
logToConsole('onSubmitInst OK'); // Is NOT logged
// ... more code ...
}
解决方案
如果脚本作为附加组件发布或绑定到文档,则从文档中PropertiesService.getDocumentProperties()
返回有效对象。Properties
否则返回null
。
无论哪种方式,它都不会触发您的try -> catch
,null
返回不是异常并且不会生成错误消息。
您必须检查返回的对象是否null
有效,并相应地调整您的逻辑。
docProps = PropertiesService.getDocumentProperties();
if (docProps === null) {
logToConsole('onSubmitInst property returned null');
return;
}
参考:
推荐阅读
- c# - 如何从表单中的列表框计算总数
- php - 比较 2 个表的 2 个名称字段并检索匹配的名称字段的 id
- css - 在调整大小浏览器上,我的内容也有不好的位置和背景
- python - 如何从客户端输入过滤 ModelAdmin autocomplete_fields 结果
- javascript - 将图像元素推入数组
- git - 仅在更改某些文件时运行 Azure Pipelines 作业
- filenet-p8 - IBM FileNet 修订包 5.2.1.7 安装了两次
- python - 从 .txt 文件复制文本并将其分配给 Python 中的变量
- c - 使用 CreateprocessA/W 时是否使用 system() 函数?
- java - View pager Recycler view Fragment transition with shared element