I wrote a script to add tags and modify color of Google Calendar events. The script :
- select some events based on date range
- apply some rules on the selected events
The script itself work just fine and is launched on a timely basis. However, if I set up a trigger based on the update event trigger, then :
- script will launch OK
- events are updated
- each event updated triggers a new launch of the script => Infinite Loop.
There has to be something that I do not understand about this trigger. How to prevent thos multiples executions ? Basically, I would like to "disable" the trigger while the script is running.
Many thanks,
Nico.
Tried :
- using tags to record the events already processsed, but I still have the issue if I force the update
- implementing this function
The code is like :
var hasLock = new Boolean(false)
function onCalendarEvent() {
// lock to prevent multiple executions of script
if(DEBUG) {
console.log("Event based laucnh. Lock is " + hasLock)
}
if (hasLock == false) {
hasLock = true
if(DEBUG) { console.log("Calling function") }
colorizeEvents(0)
hasLock = false
}
}
function onCalendarEvent() {
// do stuff : select events and update them
}