0

I implemented a Google Calendar AddOn for hundreds of users which also installs a calendar trigger for each user to run some business logic whenever something changes in the user's calendar. The trigger code is located in a different AppScript and added to the AddOn AppScript Project as library.

Whenever the user opens the AddOn I delete the trigger calendarEventTrigger by name and install it again to make sure only one instance is running and everything is up to date.

This works so far, however when I was reviewing the logs in the Log Explorer I spotted a periodically error:

Script function not found: calendarEventTrigger Which, when I understand the label project_key correctly comes from the AppScript project where the trigger code is located and not the AddOn.

So how is that possible? This makes no sense to me.

This is the code where I install and delete the trigger from the AddOn:

const triggers = ScriptApp.getProjectTriggers();
  triggers.forEach((trigger) => {
    const funcName = trigger.getHandlerFunction();
    if (funcName === "calendarEventTrigger") {
      ScriptApp.deleteTrigger(trigger);
      Logger.log("Removed calendarEventTrigger.");
      Utilities.sleep(1000); //wait to avoid "too many times" error;
    }
  });

According to the label user_key it only happens to a bunch of users.

And here is the part where I install the trigger:

try {
    ScriptApp.newTrigger("calendarEventTrigger")
      .forUserCalendar(user)
      .onEventUpdated()
      .create();
  } catch (error) {
    Logger.log("Error creating trigger");
    Logger.log(error);
  }
zlZimon
  • 2,334
  • 4
  • 21
  • 51
  • Sounds like the error is implying the trigger is not installing, rather not being removed. Could you include the installation portion of your code? – NEWAZA May 31 '22 at 19:41
  • Thanks, I added the part where I install the trigger, which is right after the first block – zlZimon Jun 01 '22 at 06:26

0 Answers0