0

The objective is to transfer data from Google Calendar to a Google Sheet whenever the calendar is edited. For this we need a script that transfers the data, and need to set up the Calendar trigger.

Thanks to Oleg Valter and his excellent and exhaustive explanation how to create the script on this page:

Google calendar events to Google spreadsheet automatic refresh onEdit

the data transfer already works fine when the script is started from the Google sheets. I use a modified version of Oleg's script, which works well, and I am not sure if it would make sense to re-post it here (since that is not the problem).

I have tried to create the trigger with Oleg's funtion first:

/**
 * Installs Calendar trigger;
 */
function calendarTrigger() {
  var trigger = ScriptApp.newTrigger('callback name here')
  .forUserCalendar('calendar owners email here')
  .onEventUpdated()
  .create();
}

but the trigger did not fire when I have added a new event on the calendar. Checked the triggers connected to the project, and the trigger created by the above function was there. Checked the Executions and nothing showed up.

Then I have manually deleted the trigger, and manually crated a new one following the instructions under "Managing triggers manually" section of this page:

https://developers.google.com/apps-script/guides/triggers/installable#google_apps_triggers

The trigger was created again, which basically looked the same as the one created by the above function, but it still did not fire when tested.

Now I am stuck and have no idea what else to try. It supposed to work, but it is possible that I have missed setting up something else that might be required for this to work.

I am using a simple Google account connected to a single email address (not a business suite). Never had any problems with the other triggers related to the sheets before that I could not resolve (sometimes the platform refuses to work as it should, but then later things get back to normal).

I would highly appreciate any advice about what else to try, or if you know what the problem is, even better.

Thanks in advance,

Zoltan

Z_Losonc
  • 41
  • 6
  • Three questions: 1. Are you the owner of the calendar you want to access? 2. How do you specify `'calendar owners email here'`? Do you set the email in quotes? 3. How do you specify `'callback name here'`? It should contain the name of the function to run on trigger. – ziganotschka May 07 '20 at 12:58
  • 1. Yes I am the owner, using the same email adders as the spreadsheet. 2. Yes, using " character "myaddress@yahoo.com", 3. "updateSpreadsheet" this is the name of the function that transfers the data, and it works fine. – Z_Losonc May 07 '20 at 13:10
  • I have just added an installed onEdit trigger as well to test if it works or not (although not needed for the project), and it works fine. But the Calendar trigger does not fire. – Z_Losonc May 07 '20 at 13:17

2 Answers2

1

Well, after some trial and error based on ziganotschka's kind answer (thanks again) found the problem. It is caused by a bit of confusion about what the

.forUserCalendar('calendar owners email here') and the

Calendar ID supposed to be.

On my Calendar account there are several calendars, but two are of interest for us here:

  1. "Main Calendar" which is the default calendar associated with the account. If everything else is deleted, then this will remain.

  2. another calendar that I have added for the very purpose to be connected to the spreadsheet, and named it "Auto Billing" (only this is checked and displayed).

The Main Calendar has this on the Settings page (changed my email address):

Integrate calendar

Calendar ID

myAddress@yahoo.com

The Auto Billing calendar has this on the Settings page (changed the ID):

Integrate calendar

Calendar ID

svj8tu1o458a9s1488xxxxxxxx@group.calendar.google.com

My intent was to use a custom created calendar for this purpose instead of using the default Main Calendar, because this might be full with all kinds of events.

Therefore when the trigger is created manually

svj8tu1o458a9s1488xxxxxxxx@group.calendar.google.com

should be added in the field "Calendar owner email" instead of the calendar owner's email address.

When the trigger is created from script using the above snippet, then

.forUserCalendar("svj8tu1o458a9s1488xxxxxxxx@group.calendar.google.com")

should be used.

In the script that transfers the data from the Calendar to the sheet the

var Calendar = CalendarApp.getCalendarById("svj8tu1o458a9s1488xxxxxxxx@group.calendar.google.com");

should be used. This way the trigger will work when events are edited on the Auto Billing calendar.

Thanks for the guidance Ziganotschka, and also big thanks to Oleg for the original script. Hope this debugging will help others as well.

Z_Losonc
  • 41
  • 6
0

Google Calendar trigger is a feature for the Google Calendar

It does not work for "myaddress@yahoo.com" calendars

ziganotschka
  • 25,866
  • 2
  • 16
  • 33
  • 1
    Thanks ziganotschka for the answer. Do you mean that if I use myaddress@gmail.com instead of yahoo.com then it would work? I assume it supposed to be able to trigger a Google sheets connected Apps script function, since the Oleg's original script was based on this feature to work. – Z_Losonc May 07 '20 at 13:48
  • Update: I have just tested, and the trigger does fire when it is set up with "myaddress@yahoo.com" as Calendar ID (instead of svj8tu1o458a9s1488xxxxxxxx@group.calendar.google.com). But only when the main calendar of the Google Calendar account is edited. It does not fire when any other calendar in the same account is edited. If the main calendar is watched, then .forUserCalendar("myaddress@yahoo.com") and var Calendar = CalendarApp.getCalendarById("myaddress@yahoo.com"); should be used in the scripts. – Z_Losonc May 09 '20 at 12:16
  • If your Yahoo account is linked to the Google calendar - then yes, it does work. Sorry for the misunderstanding - I thought that you are trying to fetch events from a Yahoo calendar which is not linked to Google calendar. – ziganotschka May 09 '20 at 17:06
  • I can log into one of my Google accounts using my yahoo email address, and into my second Google account using my gmail address. I mostly use the one connected to my yahoo email address, and the discussed Calendar is also in that account. Your hint that the problem might be with the email address (or with the Calendar ID) has lead me to figure out how this works. Thanks for the input. – Z_Losonc May 10 '20 at 18:57