0

I can't get the simple example copied from the google dev site to work.

The error is: Cannot call FormApp.getUi() from this context

I am NOT attempting to deploy this a web form/app but I am simple trying to run this via the editor!!!

Not sure what I'm doing wrong?!?!?!

The following has been pasted into index.html:

<!DOCTYPE html>
<html>
  <head>
    <base target="_top">
  </head>
  <body>
    Hello, World!
  </body>
</html>

The following is pasted into Code.gs:

// Use this code for Google Docs, Forms, or new Sheets.
function onOpen() {
  FormApp.getUi() 
      .createMenu('Dialog')
      .addItem('Open', 'openDialog')
      .addToUi();
}

function openDialog() {
  var html = HtmlService.createHtmlOutputFromFile('Index');
  FormApp.getUi() 
      .showModalDialog(html, 'Dialog title');
}
Rubén
  • 34,714
  • 9
  • 70
  • 166
Walter
  • 173
  • 1
  • 13
  • I just tried running the `openDialog()` function from the code editor, and it *did* open a dialog box in a Form that is bound to the script that I used. Do you have a Form open in edit mode? – Alan Wells Dec 09 '16 at 02:53

1 Answers1

1

Answered my own question.

The script must be bound to a Form (which mine wasn't!)

So now I need to figure out how to create a Dialog for an Unbound script.

I don't think this is possible!

If I deploy it as a Web App then obviously I have no access to the user UI.

So how would I take the output from ContentService.createTextOutput() and cause a download of a file to occur?

Walter
  • 173
  • 1
  • 13