My favorites | Sign in
Project Home Wiki Issues
New issue   Search
  Advanced search   Search tips   Subscriptions
Issue 395: Add getEventById() method to Calendar object.
69 people starred this issue and may be notified of changes. Back to list
Status:  Fixed
Closed:  Feb 2012

Sign in to add a comment
Reported by, Jan 6, 2011
Request Summary:

We should be able to do:

 var event = aCalendar.createEvent(...);
 var eventId = event.getId();

and later do:

 var anEvent = aCalendar.getEventById(eventId);

The use case here is to push changes to a calendar event from a spreadsheet onEdit() trigger.  For example, to update the title of an event, or to reschedule it.
Jan 6, 2011
Great feature request! I'm surprised this isn't available yet -- looking forward to it's implementation.
Jan 18, 2011
Project Member #2
(No comment was entered for this change.)
Status: 3365792
Labels: Component-CalendarService
Mar 6, 2011
I'm looking for the same feature.
Somebody, if there is a workaround to address the same problem?

Apr 4, 2011
Right, this is urgently needed.
Apr 6, 2011
It is required to update calendars when input comes from an external application.
Apr 6, 2011
Ehh, I'd say that the workaround seems fairly straight forward.
Implement your own .getEventById function, to:

//Step.1: Get all events in the desired Calendar, by calling
//Using "absurd" start & end dates in past & future (ex. 1.Jan.1970 & 31.Dec.2099)
//(Need to test: GAS in 2038

//Step.2: Loop through all events returned, looking for match on EventID, by calling

Apr 6, 2011
Comment 6 would be appropriate if your calendar didn't have many events, or if you could tolerate slow-running scripts.  That workaround is not suitable for my use-case.
Apr 6, 2011
If you need performance, then pure GAS is not for you.
You'll need the API:
Apr 6, 2011
If you need super-performance, GAS is not for you. If you simply want reasonable performance from GAS, then a getEventById makes a ton of sense. If performance isn't a concern, the workaround should work in the meantime.
Apr 6, 2011
My use-case is to update a specific calendar event during the onEdit() trigger of a spreadsheet.  So as to keep the information in calendar event in synch with the information in the spreadsheet.

getEventById() in an onEdit trigger is a simple and effective way of achieving this.

Sure, I could use the Calendar API, if I could export the triggering event outside GAS.  The only 2 strategies I'm aware of are:

a) noticing that a row had changed by polling for any change to the sheet via the Spreadsheet API (in practical terms, this means I will also need a 'last modified' column in my sheet, but that's OK).

b) exporting the triggering event using a GAS UrlFetch in the trigger, to push certain values to a service that could then use the Calendar API to update the calendar event.

Either of these strategies might perform better than getting all events in the calendar each time one handles a GAS onEdit trigger.  But it's going to perform worse than, and is sure is a whole lot more coding and production-system-uptime rigmarole than having getEventById() in the GAS API.
Apr 6, 2011
In theory, if the spreadsheet will be holding the event's ID anyway... you could just store the ID *and* the current date/time of the event in the spreadsheet. Then, rather than using "absurd" start and end dates to get all events for the calendar, you'd just use getEvents to get all events for that specific date/time. This should greatly reduce the number of events you'd need to cycle through to match on the ID.

You'd just want to make sure if you are changing the event's date/time, that you also update this in the spreadsheet's "current date/time" field(s) when you change the event's date/time, so that you can still match on the new schedule later.
May 26, 2011
I need a getEventById() method too! For the same reasons!
Jun 9, 2011
Hi there,

I also need this. Of course, you can store event date with event id within spreadsheet, but what if user change the date in calendar? This method is a must.
Jul 18, 2011
#14 Gurianov
I've used a workaround for this issue even before it was started. But it very inefficient. For now I've performance problems and need to rewrite this code.
Could we know when such method (getEventById()) would be available?
Sep 30, 2011
I'm trying to implement a script to add time travel to my events.
To do this, my time travel events hold the Id for event where they belong. I also want to use the getEventById() feature to find the event back.
Nov 24, 2011
This is a necessary feature, especially if you are trying to keep two systems in sync and don't want to trawl through the entire feed to find the event (since you may have many items you are keeping in sync).
Dec 6, 2011
Really desperately need this.
Amazing that such a thing was left out in the first place.
Dec 13, 2011
C'mon Google, this is basic stuff.
Dec 13, 2011
This is a must have...  My firm and my clients are suffering because of the lack of this 'fundamental' function.
Jan 15, 2012
Two reasons I need/want this - 1) time performance hit to crawling over a day's events to find the one I want and 2) the accursed query limit for Google API transactions.  Seems I'm always running up against this so using up 20+ of my hourly/daily queries just to find one event doesn't work for me.

Eric B.
Jan 17, 2012
Hello everyone,

We understand that this method would make your experience with Apps Script a lot smoother. We are working on adding this feature. Thank you for your patience and interest in improving Apps Script.

Jan 17, 2012
On the other hand, thanks for the great service!  The more I play around with Google Apps the more I like it.

Eric B.

Jan 24, 2012
(No comment was entered for this change.)
Status: Triaged
Labels: log-3365792
Feb 23, 2012
A new method has been added to the Calendar class: getEventSeriesById().
You can find the documentation for this method here:

The id you provide can be either the id of a CalendarEvent or a CalendarEventSeries.
Status: Fixed
Feb 23, 2012
Thank you Google !
Feb 23, 2012
Careful.  If you implement other user-requests in a <14month timeframe, you'll get a reputation for being responsive to your customers!  (Bring it on - we're ready to be shocked!)

Thanks anyhow.  Time to do some coding.
Feb 23, 2012
sounds delicious, can't wait to try it out! Thank you google & the team of jklein...
Feb 24, 2012
Feb 27, 2012
#29 philridout
Good news, thanks
Mar 4, 2012
Somehow I don't feel like this fixes anything... an event series is not an event. It doesn't return an event, it returns an eventseries... which you can't changes the dates on. Seems "not fixed" to me.
Mar 5, 2012
@30, does this work:

 aSeries.setRecurrence(new Date(), null);   // ??

(I must admit, I haven't tried it yet ... getting back to some old code after 14 months, well...).  If that works, you could certainly raise an issue to get some competent documentation on the CalendarEventSeries object.
Mar 7, 2012
Seems to me that an Event doesnt have an unique Id, 
CalendarEvent.getId() will return the associated EventSeries.Id 

When an event is part of an EventSeries all events on that EventSeries have the same Id, so this will always be the EventSeries Id, not a proper event unique Id. 

Mar 7, 2012
@32, maybe it's better to think of an 'EventSeries' as a 'RecurringEvent'.
 If you look at the API, CalendarEvent and CalendarEventSeries have exactly
the same members ... except where it comes to 'time related' properties.
 With the more flexible CalendarEventSeries (aka RecurringEvent), the
time-related properties are encapsulated in a Recurrence object.

 (oh, and documentation for addEmailReminder is missing from
CalendarEventSeries despite the addPopupReminder suggesting it is there

Good luck.
Mar 27, 2012
We need this!!
May 5, 2012
While the getEventSeriesById is useful, it still does not fulfill the requested functionality.

It would be acceptable if you could call event_series.getEvents -> Events[]. This would allow direct access to the event object which allows for things like event.deleteEvent.

I am puzzled as to why something so simple as:

event = calendar.getEventById( event_id );

is so difficult/impossible. This silly EventSeries wrapper which allows access to the "'time related' properties" is useless for what I am trying to accomplish.

Thoughts? Comments? Responses?

I am certainly reasonable, and answers are condoned, even if it is to say, "we will not implement this feature beacause...".

Thank you.

May 7, 2012
Agreed w/ Jeff, thats actually what I need to use on a spreadsheet-calendar
Em 05/05/2012 16:43, <> escreveu:
Oct 21, 2012
is there any status on this? i also need the geteventbyid method
Dec 13, 2012
2 years now. Any news?  

"getEventbyid()" seems to me a top priority to update an event.
Dec 13, 2012
I don't know maybe the answer is so obvious they expect we find it for ourselves, or we are missing some design guidelines here..
Feb 2, 2013
getEvents method on CalendarEventSeries objects would be nice..
Feb 13, 2013
we can get email messages by id out from a thread, we can get docs by id out of a folder, but can't get a unique id for an event? and we can get links/urls to all other services' unique objects but not to calendar events. why does google keep messing with us like this? get all your services on the same page so to speak.
Feb 13, 2013

If you want to delete an event and all it's recurrences, do this:

  event = calendar.getEventSeriesById(event_id);

If you just want to change the times when an event recurs, do this:

  event = calendar.getEventSeriesById(event_id);
  recurrence = CalendarApp.newRecurrence().addDailyRule().times(5);
  start = new Date('December 25, 2013 22:00:00');
  stop = start + (4 * (1000 * 60 * 60));  // plus 4 hours
  event.setRecurrence(start, stop, recurrence); // event between 10pm and 2am, starting Dec 25, and the following 5 days
If you want to read "the time" of an event, do this:

  event = calendar.getEventSeriesById(event_id);
  theFirstTimeTheEventHappens = event.setTitle(event.getTitle());
  time = theFirstTimeTheEventHappens.getStartTime();

OK ... so that last one is a hack.  A 'getInitialOcurrence()' method would be nicer than e.setTitle(e.getTitle()) to avoid an unnecessary mutation.

Why not getEvents()?  There could be an infinite number of them, if the recurrence rule is 'Every Wednesday'.  *That* will kill your script performance for you.

Can people stop whinging about it now, please?  Go launch a ticket for adding getInitialOccurence() to CalendarEventSeries.  Go launch a ticket for 'walking' the EventSeries starting with a given date.  Go launch a ticket for Recurrence.doesThisDateMatch(d);  Whatever your use-case is.  In a rare show of faith to its users, Google fixed this one already, and I can getEventSeriesById(id).setRecurrence() to push days/times of events at the Calendar ... from my script.  Oh bliss.  

If only Google Spreadsheets wasn't already dead ...
Feb 13, 2013
I have tried this:

  event = calendar.getEventSeriesById(event_id);

but, surprisingly I still can get all the information about the deleted event as below:

  event = calendar.getEventSeriesById(event_id);

These make no different for deleted events and non-deleted events. 
Hope that google could have something like event.getDeleted()

Feb 18, 2013

Have you ever tried your code for retrieving the start time of an event. The API-documentation of <Class CalendarEventSeries> says that <method setTitle(title)> returns a CalendarEvent, but obviously it is rather a CalendarEventSeries than an CalendarEvent since executing your code like

>  event_id = cal.createEvent("Busy", new Date("July 21, 2010 08:00:00 EST"), new Date("July 21, 2010 09:00:00 EST"), {location:'Nap room'}).getId();
>  event = calendar.getEventSeriesById(event_id);
>  theFirstTimeTheEventHappens = event.setTitle(event.getTitle());
>  time = theFirstTimeTheEventHappens.getStartTime();

I get

"Error occured: TypeError: Funktion getStartTime in Objekt CalendarEventSeries not found"

So in my opinion there is no reason for "stop whinging about it now" :-( Seems to me Google doesn't us want to change CalendarEvents from GAS :-(((

Feb 19, 2013
No, and that is clearly a bug, so file a new issue (one that is not
closed!) So they can hear about it.  Post the URL here so folk can star the
new one.
Mar 29, 2013
This should not be listed as fixed. The "fix" does not address the issue of getting an event (not an eventseries) by id.
Mar 30, 2013
Just as an aside, we are changing calendar events in our applications. But we have to register all events in a separate table for this, i.e. organize the calendar data ourselves and use the calendar for presentation and sharing.
Apr 3, 2013
Here, here! The original issue is still not fixed. There is a new and currently open issue in the tracker...

No comments have been added there since June 27 2012, while 11 have been added to this "Fixed" issue.
Apr 18, 2013
this is so f'ed up! I can't change an event's date because when I getEventSeriesById (which is the ONLY way google let's us) I have no access to any of the CalendarEvent abilities like setAllDayDate because GAS views it as an event series (the log shows a single event called up as a series!!). So after a few hours of searching - came across this elegant (not) solution on SO:

Turns out, according to the link, my best shot for changing the date on a single event is to DELETE it and then Create a whole new event - that's f'ed up googlers! Fix this so we can call a single event by ID just like we can in every other freakin part of GAS
May 29, 2013
LOL, guys, u seriously? I have an even in calendar, have it's id. I want to modify start and end dates of it. So I have to delete the even and create the same again? I'm crying. Please fix this :))))
Sign in to add a comment

Powered by Google Project Hosting