6

I have a Google Sheets Add-on which uses the dialog boxes provided by the App Script Ui service, i.e., SpreadSheetApp.getUi().alert(...). This normally works fine unless a user does not select an option or close the alert within 5 minutes (say they switch to a different tab or leave their computer), in which case a "Timed out" exception is thrown.

My code:

var ui = SpreadsheetApp.getUi();
var response = ui.alert(msg, ui.ButtonSet.YES_NO);
return (response == ui.Button.YES);

And the error in the Apps Script execution transcript:

[18-02-27 16:40:18:080 EST] Starting execution
[18-02-27 16:40:18:096 EST] SpreadsheetApp.getUi() [0 seconds]
[18-02-27 16:45:18:160 EST] Ui.alert([Are you sure you want to delete this 
thing?, YES_NO]) [300.063 seconds]
[18-02-27 16:45:18:166 EST] Execution failed: Timed out waiting for user 
response (line 289, file "Code") [300.066 seconds total runtime]

After the exception is thrown the alert is still visible, and if a user comes back and hits "Yes" the above function still does not return true. It just closes the dialog and the user has to try again.

If I only add a try/catch around the alert, the user won't know that the alert has become useless after 5 minutes. Ideally I could call something like alert.close() but there is no methods like that I can find. Is there a better way of dealing with this, or should I just switch to using HTML/javascript for the alerts?

  • You might try setting a flag in PropertiesService or CacheService that indicates which particular alert got fired, and when the alert is closed, remove it from the data storage. Then when the function runs again for that user, it would check to see if a particular flag exists and if so, "jump ahead" (if possible) to offer that prompt and prompt context. – tehhowch Feb 28 '18 at 00:35
  • 3
    Any reason you cannot use [modal dialog box](https://developers.google.com/apps-script/reference/base/ui#showmodaldialoguserinterface-title). This way the user can walk away and come back still run the remaining code? Or is it that you are just checking, before you go that route. – Jack Brown Feb 28 '18 at 00:50
  • 1
    @JackBrown I was checking, since googling the "Timed out waiting for user response" returned very little results, which made me think I was doing something completely wrong. I think I will likely go the modal dialog box route, since in the end that offers more flexibility anyway. – user1754115 Feb 28 '18 at 18:18

0 Answers0