I recently created a script associated with a spreadsheet. It is a wood supply chain simulation game score viewer. Basically, it fetch (with Urlfetch) the game database to keep track of scores for every team playing in tables and graphs. The spreadsheet is then shared to every team member, which can see the progression of the game.
So I used an installable onMinute time trigger to refresh the spreadsheet with updated score from the database. Everythings was working, but recently, I started to receive app-script-notifications of failure with error :
Service invoked too many times for one day: urlfetch.
I then realised that the installable triggers are executed when the documment is not open, which is totally logic. Also, since developpement mode, I had quite a lot of the spreadsheat copy (je comprend pas sa), which explains the reach of my quota. Altough, I only need to refresh the scores for my application when the document is open.
Here are my questions :
- Is the installable onMinute time trigger the right way to do that?
- Is there a way to make the trigger run only when the document is open?
This is my first question here so feel free to post useful comments to allow me to improve.
Thank you.
Unless you can write code on the game side to push the changes to the spreadsheet, which would use less resource on both sides, a time-driven triggers seems like the only “automatic” way to go.
I say automatic, because you could change it to “on-demand”. I mean, you could add a menu to your spreadsheet or an image (where you can assign to run a script on click), that will update the scores.
This could also be semi-dynamic, for example, when the user clicks the button, you start to update the scores automatically (setting up the time-driven trigger programatically) for the next 30 minutes or so.
Asking your question n.2: no, it is not possible. Well, only half-way. Because you can detect when the spreadsheet is opened (by setting a on-open trigger), but you can’t know when it is closed.