Home > Mobile >  Exception: Cannot call FormApp.getUi() from this context
Exception: Cannot call FormApp.getUi() from this context

Time:10-20

I'm new to google script, and I keep getting the same error (in the title). I have tried to open the form in both editor and preview mode, and have moved to code to the onOpen() function. Here is the code that gives the error:

function onOpen(e){
  FormApp.getUi().createAddonMenu().addItem('Settings','show').addToUi()
  ScriptApp.newTrigger('submit').forForm(FormApp.getActiveForm().getId()).onFormSubmit().create()
}
function show(){
  ...
}
function submit(){
  ...
}

CodePudding user response:

All I had to do to get it working again was remove the code, run the project, then add it back in.

CodePudding user response:

You should never create triggers inside the onOpen method as it is a simple trigger and will fail for users who have not authenticated the script.

If the script is authenticated, it will try to create a trigger everytime the form is opened in the Google Forms editor and may cause your script to fail.

  • Related