I have a Google Sheet that runs some Apps Script server code to connect to an SQL server. I want to show the message \"loading...\" in the modal dialog while data is being
//show dialog
var output = HtmlService.createHtmlOutput('<b>Please wait...</b>');
SpreadsheetApp.getUi().showModalDialog(output, 'Saving...');
some code
//close dialog
var output = HtmlService.createHtmlOutput('<script>google.script.host.close();</script>');
SpreadsheetApp.getUi().showModalDialog(output, 'Loading...');
*optional
ui.alert("Saved Successfully!")
The flow of events could be:
onLoad
event of modal dialog triggers client side codegoogle.script.run
triggers a server side .gs
function to run.gs
script file runs.google.script.host.close();
You'll need a <script>
tag in your modal dialog.
<script>
window.onload = function() {
//console.log('window.onload ran!');
google.script.run
.withSuccessHandler(closeDialog)
.theFunctionNameToUpdateDatabase()
};
window.closeDialog = function() {
google.script.host.close();
};
</script>
Right now you are using:
HtmlService.createHtmlOutput(the HTML here)
You could create the HTML from a file instead:
HtmlService.createHtmlOutputFromFile(filename)