Atiq Zabinski
Atiq Zabinski

Reputation: 133

Error using Template HTML in Custom Dialog Box: "We're sorry, a server error occurred. Please wait a bit and try again"

I'm trying to add to a sheet a custom dialog box created from HTML template, and nothing I do has any outcome but this error: "We're sorry, a server error occurred. Please wait a bit and try again."

To eliminate all chances of error on my part, or conflict with anything I'd already written, I put aside my project, and started over with a blank spreadsheet. I added to it absolutely nothing but the code Google recommends at https://developers.google.com/apps-script/guides/html/templates

function doGet() {
  return HtmlService
  .createTemplateFromFile('Index')
  .evaluate();
}


<!DOCTYPE html>
<html>
  <head>
    <base target="_top">
  </head>
  <body>
    Hello, World! The time is <?= new Date() ?>.
  </body>
</html>

I'm STILL getting the error. Apart from a very simple Custom Menu that enables you to invoke this function, there isn't a thing in my code apart from this function and HTML copied and pasted from Google Developers. I have tried some of the other examples on that page, but no matter what function I try, the result is this same cryptic error message.

Here is the Google Sheet; see if you can get that function "Do Get" to work: https://docs.google.com/spreadsheets/d/1RpbYryy0El80oj-07Q21cbtRr8gPDCjrwPbHbBF4Zr0/edit#gid=0

Upvotes: 0

Views: 143

Answers (1)

ziganotschka
ziganotschka

Reputation: 26836

For displaying a custom dialog you cannot directly return the html content.

You need to use the method showModalDialog(userInterface, title).

Sample:

function onOpen() {
  customMenu();
}

function customMenu () {
  var ui = SpreadsheetApp.getUi();
  ui.createMenu('🐬')
  .addItem('Dialog','showDialog')
  .addToUi();
}


function showDialog() {
  var dialog = doGet();
  SpreadsheetApp.getUi().showModalDialog(dialog, 'This is the dialog version of the WebApp');
}

function doGet() {
  return HtmlService
  .createTemplateFromFile('Index')
  .evaluate();
}




Upvotes: 1

Related Questions