无法从绑定的Google Forms脚本调用FormApp.getUi() [英] Cannot call FormApp.getUi() from bound Google Forms script

查看:105
本文介绍了无法从绑定的Google Forms脚本调用FormApp.getUi()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

正如标题所述,我正在尝试从脚本获取Google表单的用户界面,以便可以向用户显示带有一些信息的警报框.

As the title says, I'm trying to get the UI of a Google Form from a script, so that I can show an alert box to the user with some information.

这是函数的相关部分:

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

此代码在提交表单时"事件触发器上执行.几秒钟后,我总是收到一封包含此错误的电子邮件:

This code executes on the "On form submit" event trigger. Invariably, a few seconds later I get an email containing this error:

Cannot call FormApp.getUi() from this context.

现在,来自我的理解,绑定了脚本(像这样的脚本,是通过工具->脚本编辑器从表单创建的).应该有权访问表单的ui.

Now, from my understanding, bound scripts (like this one, it was created from the form via Tools -> Script Editor) should have access to the ui of the form.

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

I already tried calling the same function from SpreadsheetApp, in case the form response automatically switched to the spreadsheet, but no dice. I also tried saving a (global) reference to the UI from a function called by the "On open" trigger, but that too failed.

我想念什么?

推荐答案

这无法响应表单提交,您实际上无法实时"与面向用户的Google Form的用户界面进行交互完全没有.

This isn't possible in response to a form submission, you can't actually interact with the UI of a user-facing Google Form in "real time" at all.

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

At the documentation you linked, it states this limitation:

(请注意,在Google表单中,用户界面元素仅可见 打开表单进行修改的编辑者,而不是打开表单的用户 答复表格.)

(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.)

这篇关于无法从绑定的Google Forms脚本调用FormApp.getUi()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆