I have a project that reads a Google Sheets spreadsheet and maintains a summary of contents in another sheet. All the hooks are in place to run as needed (daily, weekly, whatever), starting where it last left off, and the unprocessed rows will affect the summary.
In case the summary sheet ever needs to be wiped out and all data reprocessed, I have added a menu option for reinitialization. Within that reinitialization function there is dialog:
var ui = SpreadsheetApp.getUi();
var result = ui.alert(
"Please confirm"
, "This will completely wipe out the summary data and start over, and may require many executions in order to catch up. Are you sure you want to do this?"
, ui.ButtonSet.YES_NO
);
if (result == ui.Button.NO) {
ui.alert("Good thing I asked!");
return;
}
(This happens only when there are design changes to the summary.)
If I am running this process in the scripts debugger, the process dies with the message:
Exception: Cannot call SpreadsheetApp.getUi() from this context.
So I would like to avoid that part of the code when debugging. How can I determine if the script is being run in that mode?