Opening Dialog Box during Calculation and Retrieving Calculated Result using Google Apps Script


  1. When it starts a calculation, open a dialog box.
  2. When the calculation is finished, close the dialog and retrieve the calculated result.

This is a sample script for achieving above flow. This sample script supposes to use the container-bound script of Spreadsheet. When you use this, please run the function of run().

Sample script:

function doSomething(e) {

  // Scripts for calculating.

  Utilities.sleep(3000); // This is a sample wait time.
  var data = "data";
  main({result: data});

function openDialogue() {
  var html = "<script> {}).doSomething();</script>";
  var h = HtmlService.createHtmlOutput(html);
  SpreadsheetApp.getUi().showModalDialog(h, "Sample");

function main(e) {
  if ("result" in e) return e.result;

// Please run this function.
function run() {
  var res = main({});


  • This can be also used for the sidebar and other Google Docs.