According to the documentation, calling a Google Apps Script function from a client HTML script should be as simple as google.script.run.myFunction()
. However it doesn't seem to work for me:
My Code
function onOpen() {
SpreadsheetApp.getUi()
.createMenu('Dialog')
.addItem('Open', 'openDialog')
.addToUi();
}
function openDialog() {
var html = HtmlService.createHtmlOutputFromFile('Index')
.setSandboxMode(HtmlService.SandboxMode.IFRAME);
SpreadsheetApp.getUi()
.showModalDialog(html, 'My Dialog');
}
function doSomething() {
var sheet = SpreadsheetApp.getActive().getActiveSheet();
sheet.getRange(sheet.getLastRow()+1, 1).setValue("Hello :)");
}
Note that calling doSomething()
from the IDE runs smoothly. However not from the HTML script:
My HTML
<script>
google.script.run.doSomething();
</script>