On a Google Sheet, I have an extensive OnOpen script (viewable here) to refresh data on several sheets within the workbook. It all takes a while for all script lines to execute, i.e. to import new raw data and to then perform five different Unique Queries against that new data and thus update data on five sheets. When the Google Sheet is opened the user does see two successive pop-up yellow "Working" boxes, then five subsequent progress bars (while each of the queries do their thing). This all takes quite a while. I'd like to make an addition to the script routine to announce to the user that "all data is now refreshed and ready to view." A simple MessageBox ("Data now refreshed') placed at the end of the scripts seems to pop up before all script commands are actually completed. Thus the message box gives misleading info and I think it also interrupts some script lines from executing until "OK" is checked. So, MessageBox doesn't seem to work. So, I'm looking for a way to confirm that all script line (and all unique queries) are, in fact, complete before informing the user that it's OK to start viewing the data. Thanks.
0
votes
1 Answers
0
votes
Place a SpreadsheetApp.flush() before the "finished" alert box; the flush()
method:
Applies all pending Spreadsheet changes. Spreadsheet operations are sometimes bundled together to improve performance, such as when doing multiple calls to Range.getValue(). However, sometimes you may want to make sure that all pending changes are made right away, for instance to show users data as a script is executing.