UPDATED: This is totally possible. I just was closing the host window before the async method completed. My interpretation was that the running context would persist, even i
Instead of using HtmlService.createTemplateFromFile
you could use:
HtmlService.createHtmlOutputFromFile('simpleDialog');
Here you can find more information about this function https://developers.google.com/apps-script/guides/html/
The culprit here is this line in onSave()
function:
google.script.host.close();
Remove/comment this line and the script runs fine. The error you see is because you close the sidebar with that line, severing connection to the server-side script.
If you do need to close the sidebar after onSave()
has finished executing, move that line to the success handler callback:
function onSave(){
google.script.run
.withSuccessHandler(onSuccess)
.withFailureHandler(onFailure)
.doWorkInAppsScriptFile();
}
function onSuccess(data)
{
// do something with returned data
// close the sidebar
google.script.host.close();
}
function onFailure(error)
{
alert("onFailure: " + error);
}