Since the beginning of this month this code has not more been working
function onEdit(e){
var html = HtmlService.createTemplateFromFile( 'MyHtmlFile' )
.evaluate()
.setWidth( 800 )
.setHeight( 400 );
SpreadsheetApp.getUi() // Or DocumentApp or FormApp.
.showModalDialog( html, 'My page title' );
}
When I edit a Spreadsheet's cell NO pop up is shown but I got this error in the console:
Google Apps Script: You do not have permission to call showModalDialog
The onEdit()
will have to be an Installable Trigger because it is using a service that requires authorization.
note: rename onEdit()
when using it as an installable trigger to avoid possible issues
Like simple triggers, installable triggers let Apps Script run a function automatically when a certain event, such as opening a document, occurs. Installable triggers, however, offer more flexibility than simple triggers: they can call services that require authorization, ...
Managing triggers manually:
To manually create an installable trigger through a dialog in the script editor, follow these steps:
This answer serves documentation purposes.
onEdit
trigger via a script if you want to avoid the manual work of installing the trigger.In order to create an installable onEdit
trigger for myFunction
, execute only and once the create_onEdit
function below:
function myFunction(){
var html = HtmlService.createTemplateFromFile( 'MyHtmlFile' )
.evaluate()
.setWidth( 800 )
.setHeight( 400 );
SpreadsheetApp.getUi() // Or DocumentApp or FormApp.
.showModalDialog( html, 'My page title' );
}
function create_onEdit(){
ScriptApp.newTrigger('myFunction')
.forSpreadsheet(SpreadsheetApp.getActive())
.onEdit()
.create();
}
References:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With