异常:找不到具有给定 ID 的项目。可能是因为您尚未编辑此项目或您无权访问它

Exception: No item with the given ID could be found. Possibly because you have not edited this item or you do not have permission to access it

我有以下设置:

大多数时候一切都按预期进行,但有时我会收到此错误消息:“异常:找不到具有给定 ID 的项目。可能是因为您尚未编辑此项目或您无权编辑访问它。"

我尝试了以下方法来重现这种情况,但没有成功:

有什么想法吗?


附件是我可安装的表单提交处理程序的最少代码。 看来,读取文档属性会导致错误。 尽管我应该被允许阅读这些属性,因为函数是 AuthMode.FULL 模式下的 运行。

function onSubmitInst(event) {
    console.log(event.authMode === ScriptApp.AuthMode.FULL); // In case of error --> logs always true

    console.log(ScriptApp.getAuthorizationInfo(ScriptApp.AuthMode.FULL).authInfo.getAuthorizationStatus().toString()); // In case of error --> sometimes "REQUIRED", sometimes "NOT_REQUIRED"

    var docProps = PropertiesService.getDocumentProperties(); // In case of error --> "Exception: No item with the given ID could be found. Possibly because you have not edited this item or you do not have permission to access it."

    // Other code following ...
}

我想知道错误是否发生在未编辑表单的协作者(表单编辑者,而不是所有者)身上。

这个“解决方法”怎么样?

在使用 try...catch 创建触发器的附加功能上尝试获取文档属性。如果有错误,请插入问题,然后将其删除。

免责声明:我没有尝试过此操作,因此在将此添加到您的 public 附加组件之前,您可能希望将副本发布为未列出/仅供您的域用于测试目的。

以下情况产生错误:

  • 用户 A 可以访问表单并激活插件/表单提交触发器
  • 用户 B 也可以访问表单
  • 用户 A 已从表单中删除(重要提示:触发器仍然存在于 his/her 环境中:https://script.google.com/home/triggers
  • 用户 B 继续进行调查,假设用户 C 提交了表单
  • 用户 A 的其余触发器触发并产生错误