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

余生颓废 提交于 2020-06-25 21:50:10

问题


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.

This is the relevant part of the function:

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.

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.

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.

What am I missing?


回答1:


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:

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



来源:https://stackoverflow.com/questions/33353333/cannot-call-formapp-getui-from-bound-google-forms-script

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!