google-sheetsgoogle-apps-script

Updating the user during functions triggered by time driven triggers


I have a series of functions that run one after the other based on a series of time-driven triggers (when one finishes, it creates a time-driven trigger for the next). These functions are bound to a spreadsheet for which I was hoping to run updates to the user as to which function it's on (ex. "starting script 2/5" or "finished script 3/5, script 4/5 will begin shortly").

I was doing this successfully using a toast update for the first function, which is triggered via a button on the spreadsheet. However, toasts don't seem to be working for the time-driven trigger functions. Is there an alternative way to provide updates to a google sheet? I probably could just edit a cell each time to contain an update string, but I was hoping to have something that would appear over the grid.

Hopefully that all makes sense, if not I am happy to provide any clarification needed!


Solution

  • The UI cannot be accessed from within a time-based triggered function. So any method implying an alert, opening a modal dialog or sidebar, or similar, are not possible.

    Similarly - and I'm not at all sure about what I'm about to say - since the toast method interacts with the UI, even if it is not called directly from the UI class, it probably doesn't work either.

    So three possible workarounds.

    1. Update a predefined cell with a string each time, as you suggest. Simple, but somewhat disappointing.

    2. Make the first function open a sidebar with a custom client-side script that updates automatically. Much better suited to the situation, but also much more complex and time-and-effort consuming.

    3. I don't fully understand your situation but, unless they serve some other purpose, drop the triggers altogether and switch to asynchronous programming. If adapted to your case, I would definitely go with this one.