0

I have a response google spreadsheet connected to a google form.

In the spreadsheet bound script I have and the onOpen like this:

function onOpen() {
  SpreadsheetApp.getUi() // Or DocumentApp or FormApp.
      .createMenu('Configura Gestione NC')
      .addItem('Invio eMail', 'openDialog1')
      .addToUi();
}

function openDialog1() {
 var ui = SpreadsheetApp.getUi();
  var response = ui.prompt('Inserisci la mail che riceverà tutte le comunicazioni:', 'Valore attuale: ' + PropertiesService.getScriptProperties().getProperty('emailSupervisore'), ui.ButtonSet.OK_CANCEL);

 if (response.getSelectedButton() == ui.Button.OK) {
      PropertiesService.getScriptProperties().setProperty('emailSupervisore', response.getResponseText());
     } 
    }

myScript(e){
    var SS = SpreadsheetApp.getActiveSpreadsheet();
    and do other things
}

I setup an installable trigger on the function myScript(e) that run when the form is submitted because I need to intercept form responses. When I fill and send the form I get the error:

Cannot call SpreadsheetApp.getUi() from this context.

Is onOpen is run even if the trigger is set up on myScript(e)?

In my myScript(e) I don't call SpreadsheetApp.getUi()... is onOpen called automatically even during the script?

Is there a workaround to make works together SS Custom Menus and the myScript function?

Kintaro
  • 178
  • 3
  • 14
  • 1
    I would need to see more of the myScript function. onOpen is a simple installable trigger so it has some restrictions associated with it. https://developers.google.com/apps-script/guides/triggers/ – Jordan Rhea May 25 '17 at 16:46
  • as mentioned above, we need to see more of your myScript function in which you probably call getUi()...even indirectly, and you can not do that in this context... The error message is very meaningful. – Serge insas May 25 '17 at 17:29
  • The error came up once I added onOpen function. In myScript there no getUi() call. Once I get to my desktop I will paste more code. – Kintaro May 25 '17 at 22:24
  • I simply delete the onOpen function and the sub-menu-functions related to it and the error is gone... Now I re-wrote them and I have no error. I'm confused, but now the issue is fixed. Probably I missed something that now is gone. – Kintaro Jun 02 '17 at 14:00

0 Answers0