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 refreshed. I can get the modal to pop up, but I want to auto-close the dialog as soon as the code is finished.
An example I have set up is:
function testpop () {
var htmlOutput = HtmlService
.createHtmlOutput('<p> This box will close when the data has finished loading.</p>')
.setSandboxMode(HtmlService.SandboxMode.IFRAME)
.setWidth(250)
.setHeight(200);
SpreadsheetApp.getUi().showModalDialog(htmlOutput, 'Loading...');
sleep(1000);
//close the dialog
}
I know this can be called on a client side but need it to be handled in the GS so it fires when the code is done.
1 Answer. Show activity on this post. If you are in the code editor, and want to stop a script from running, you can click the "cancel" link in the toast display. Or you can click "View" -> "Executions" from the code editor and then terminate the script.
Ui. An instance of the user-interface environment for a Google App that allows the script to add features like menus, dialogs, and sidebars. A script can only interact with the UI for the current instance of an open editor, and only if the script is container-bound to the editor.
To get the name the active sheet: var actualSheetName = SpreadsheetApp. getActiveSpreadsheet(). getActiveSheet().
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)
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