3

I'm developing a Google Calendar addon.

I want to be able to modify event fields (e.g. the title) within the addon. I have a function that runs when triggered by eventOpenTrigger. According to the documentation, we can only addAttendees and setConferenceData. I tested those functions and they are working fine for both existing and new events. Is there any proper way to modify other event fields?

I found a "dirty trick" to modify the event's title for an existing event using the CalendarApp API:

function onCalendarEventOpen(e) {
  var calendar = CalendarApp.getCalendarById(e.calendar.calendarId);
  var event = calendar.getEventById(e.calendar.id);
  if (!event) {
    // This is a new event still being created.
    return createSimpleTextCard('A new event! Am I invited?');
  }
  event.setTitle('Modified title') // imagine doing this after a button click
  return createSimpleTextCard('Modified title');
}

This trick has some drawbacks:

  1. The event page's ui that we are currently editing is not refreshing accordingly; we have to close/open the event to see the changes. Plus, if the user make any change on the modified fields, it keeps his version. Is there any way to force a "refresh" of those fields so that the user can see an up-to-date version of the event?
  2. It doesn't work with new events (for which we have no valid ID when querying the API) which would be very annoying for the addon I'm developing.

Does someone have a better solution? Am I missing something? It would be awesome to have a function setTitle that works the same way as addAttendees on a CalendarEventActionResponseBuilder.

Kallias
  • 49
  • 5
  • Have you tried using the Apps Script method [setTitlte()](https://developers.google.com/apps-script/reference/calendar/calendar-event#settitletitle) to change your event's title? You could run this on the triggered event so that you change that event title only when the specific trigger is executed : ```function onCalendarEventOpen(e) { var calendar = CalendarApp.getCalendarById(e.calendar.calendarId); calendar.setTitle('new Title);}``` – Mateo Randwolf May 18 '20 at 09:22

0 Answers0