While coding a simple Google Script for multiple non-programmer users, I noticed a strange bug. If the browser is open too long, sometimes the document doesn't link to the script anymore. Then the initial methods fail. It crashes the script. This occurs on the second line where I define the getUI:
var ui = DocumentApp.getUi();
I made a try-catch to handle the bug, but I'm at a loss on how to alert or notify the user to refresh their browser session. I can't assess the UI with getUI, so I can't use the html or alert functionality to prompt the user. Without the UI methods, is there a way to tell them info? Like a title, hint, tip, etc?
Any ideas on how to notify the user to refresh the session?
CodePudding user response:
From the question:
Without the UI methods, is there a way to tell them info? Like a title, hint, tip, etc?
In Google Sheets you might use SpreadsheetApp.toast.
Another option is to designate an element in your file, a range in Google Sheets, a paragraph in Google Documentos, a slide or shape in Google Slides, to be used to show messages to the user.
In Google Sheets it's possible to "activate" a range, this might be helpful when you want to get the user attention to it.
Apparently you are facing a problem (not being able to show a message to the user) with two different causes.
Google Apps Script has quotas, one of those quotas is the time execution limit, 6 minutes for free accounts, 30 minutes for Workspace accounts. Ui.alert() and Ui.prompt() as well Browser.msgBox() maintain the script execution waiting for user response. Unfortunately there is now way to catch the time execution errors and it's not possible to programmatically interrupt the execution while the script is waiting for a user response.
AFAIK user interfaces created using the HTML Service hasn't this problem (having a exceeding execution time limit due to waiting too much for the user response), so if you are having problems with them you might have problems related to the client-server communication, so look at the executions logs and the web browser console messages.
Related