0
votes

I have a sheet that I send out to staff (copies that are shared) but when I copy this the function onOpen does not launch the dialog box.

function onOpen() {
    SpreadsheetApp.getUi()
}

function openDialog() {
    var html = HtmlService.createHtmlOutputFromFile('Index');
    SpreadsheetApp.getUi() // Or DocumentApp or SlidesApp or FormApp.
    .showModalDialog(html, 'Math Sheet Directions');
}
1
Are inline comments allowed in this language? You have object1.object2 // comment .method(), which may be causing an error. - halfer
Please tag this with the language you are using - JavaScript? - halfer
This is in a google sheet. The script runs for me after I allowed/permissions. However, when I make a copy of the sheet the new sheet will not execute unless permissions are allowed again. - MICHAEL GARBER
Ah, OK - so it now works? - halfer
This is by design. Simple triggers are never allowed to display dialogs... - tehhowch

1 Answers

0
votes

Take a deep look on the next thread : onOpen not executing?

As you can see from the thread and Issue Tracker:

Google has restriction for onOpen functionality

Is there a different way to achieve your goal?

  • You can create a red button "Show URLs" and assign it a function.

For example:

function openDialogBox() {

  // your html content here
  var html = "<a href='https://google.com'>Google.com</a><br /><a href='https://stackoverflow.com'>Stackoverflow.com</a>" ;

  var htmlOutput = HtmlService
    .createHtmlOutput(html)
    .setWidth(250)
    .setHeight(300);

  SpreadsheetApp.getUi().showModalDialog(htmlOutput, 'URL links');

}

This is how it looks like:

Dialogbox output

We don't have any restriction here.

I know this method doesn't help you, but probably this is the only way to achieve similar behavior of what you want to do :)

Reference