无法从绑定的 Google 表单脚本调用 FormApp.getUi()

Cannot call FormApp.getUi() from bound Google Forms script

正如标题所说,我正在尝试从脚本中获取 Google 表单的 UI,以便我可以显示向用户显示一些信息的警告框。

这是函数的相关部分:

function Foobar(){
    ...
    var ui = FormApp.getUi();
    ui.alert("Foo", "bar", ui.ButtonSet.OK);
}

此代码在 "On form submit" 事件触发器上执行。几秒钟后,我总是收到一封包含此错误的电子邮件:

Cannot call FormApp.getUi() from this context.

现在,从 my understanding 开始,绑定脚本(就像这个,它是通过工具 -> 脚本编辑器从表单创建的)应该 可以访问 ui 的形式。

我已经尝试从 SpreadsheetApp 调用相同的函数,以防表单响应自动切换到电子表格,但没有成功。我还尝试从 "On open" 触发器调用的函数中保存对 UI 的(全局)引用,但这也失败了。

我错过了什么?

这不可能响应表单提交,您实际上根本无法与 "real time" 中面向用户的 Google 表单的 UI 交互。

在您链接的文档中,它说明了此限制:

(Note that in Google Forms, user-interface elements are visible only to an editor who opens the form to modify it, not to a user who opens the form to respond.)