Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Invalid Argument: Userinterface error with createTemplateFromFile

I have used createTemplateFromFile many time in the past. It lets me use an include method so that CSS and JavaScript can be broken out into a different file. But today I can't seem to make it work. Below is my test code bound to a spreadsheet. Any ideas why its not working? I tried another existing spreadsheet with a custom dialog using the technique and it works.

Code.gs

function onOpen() {
  var ui = SpreadsheetApp.getUi();
  var menu = ui.createMenu("Test");
  menu.addItem("Test", "test");
  menu.addToUi();
}

function test() {
  try {
    var html = HtmlService.createTemplateFromFile("HTML_Test");
    Logger.log(html);
    // was html.evaluate();
    html = html.evaluate(); // correction
    SpreadsheetApp.getUi().showSidebar(html);
  }
  catch(err) {
    Logger.log(err);
  }
}

HTML_Test:

<!DOCTYPE html>
<html>
  <head>
    <base target="_top">
  </head>
  <body>
    <select>
      <option value="Doc1">Document 1</option>
      <option value="Doc2">Document 2</option>
      <option value="Doc3">Document 3</option>
    </select>
  </body>
</html>

Log

[19-01-24 09:54:51:240 PST] {}
[19-01-24 09:54:51:246 PST] Exception: Invalid argument: userInterface
like image 248
TheWizEd Avatar asked Mar 05 '23 16:03

TheWizEd


1 Answers

I've been tweeking this every which way to figure out why it wouldn't work. You get blind to a simple solution. html = html.evaluate() works.

like image 184
TheWizEd Avatar answered Apr 05 '23 23:04

TheWizEd