0

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
}
5
  • 1
    Use an intermediate trigger function to disable the trigger for times while the triggered function is running
    – Cooper
    Commented Sep 4, 2024 at 18:14
  • @cooper Could you direct me on how to do that ? How can I disable a trigger ?
    – Nikomiko
    Commented Sep 4, 2024 at 20:01
  • Please provide enough code so others can better understand or reproduce the problem.
    – Community Bot
    Commented Sep 5, 2024 at 0:41
  • I wouldn't disable the trigger. Let the trigger handler be the intermediate function that calls your function whenever there is a trigger but you can disable the redirection of the trigger being redirected to it while the function is running.
    – Cooper
    Commented Sep 5, 2024 at 2:45
  • Tried to implement a simple lock based on a global variable but still have the problem :-(
    – Nikomiko
    Commented Sep 5, 2024 at 9:48

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.