Search code examples
google-apps-scriptgoogle-calendar-api

How to let others see the description added by an app script for a calendar event


I have a Google App Script that does a bunch of things and in the end sets something to the description of a Google Calendar event. It works for me, I can see the new description on calendar.google.com, but the other guests can't.

The relevant part of the code looks like:

const events = CalendarApp.getDefaultCalendar().getEvents(today, endDate)
const event = events.find(e => e.getTitle() === "My Special Title")
event.setDescription(newDescr)

If I set the description manually, from the webpage, I get prompted with:

Would you like to send update emails to existing Google Calendar guests?

And regardless of what I choose, others can then see the updated description, so I don't think it's a problem of calendar/event visibility.

The calendar that owns the event is not mine, I'm one of the guests with edit permissions.

Any idea?


Solution

  • Solution:

    Using getDefaultCalendar() only makes changes to event for the calendar of the user running the script, that is why the event owner and guests cannot see the changes made.

    Instead, use getCalendarById() as long as the calendar of the event owner is shared with the user running the script with edit permissions.

    Code.gs

    function myFunction() {
    
      const events = CalendarApp.getCalendarById('CalendarID').getEvents(today, endDate);
      const event = events.find(e => e.getTitle() === "My Special Title");
      event.setDescription(newDescr);
    
    }
    

    References:

    getCalendarById()