Search code examples
javascriptuser-interfacegoogle-apps-scriptgoogle-sheetsgoogle-cloud-platform

Auto close google app script dialog when processing is finished


I have a custom dialog that gets replaced by the below code for processing to complete. I don't want to add a link or a button to the below dialog however I want "google.script.host.close();" to close the below dialog when my code is finished processing. What am I missing?

// start processing and autoclose the dialog
  var output = HtmlService.createHtmlOutputFromFile("autoclose_progress_dialog")
                                            .setWidth(260)
                                            .setHeight(50);
  ui.showModalDialog(output, 'It will take a few secs...');

The model dialog html

<!DOCTYPE html>
<html>
  <head><base target="_top">
  </head>
  <h4>Processing your request...</h4>
  <body>
    <script>
          google.script.run.startDashboardProcessing();
    </script>
  </body>
</html>

I want the dialog to auto-close when "startDashboardProcessing()" is finished processing.


Solution

  • How about doing a google.script.host.close() in the success handler of google.script.run.startDashboardProcessing()

    Something like this:

    function onSuccess() {
      google.script.host.close()
    }
    
    google.script.run.withSuccessHandler(onSuccess).startDashboardProcessing()
    

    REF: https://developers.google.com/apps-script/reference/base/ui#showmodaldialoguserinterface,-title