Reputation: 3214
I created a small test function to try to figure out how I can delete multiple events based on a keyword.
I put two events on 1/24/2014 one named '5D - 1' and one names '5D - 2'
function testDelete(){
var calId = "<id>";
var cal = CalendarApp.getCalendarById(calId);
var date = new Date('1/24/2014/');
var Events = cal.getEventsForDay(date, {search: '5D'});
Events.deleteEventSeries();
};
But I get this error:
TypeError: Cannot find function deleteEventSeries in object CalendarEvent,CalendarEvent. (line 36, file "Code")
And that just doesn't make any sense to me. Why can't it find the function? According to this reference page it looks like it should work.
The only thing I can think of is that the object 'CalendarEvent,CalendarEvent' doesn't count as an event (I tried that) or as an event series and I have to delete the events one-by-one.
Upvotes: 0
Views: 1026
Reputation: 46794
The returned object is an array of all the events for this day. If you know there is only one event with that name you can simply use this code:
function testDelete(){
var calId = "[email protected]";
var cal = CalendarApp.getCalendarById(calId);
var date = new Date('2/21/2014/');
var Events = cal.getEventsForDay(date, {search: 'test event'});
Events[0].deleteEvent();// get first result from the search
};
if you used recurence please let me know, the code would be different...
EDIT : here is the code for eventSeries and multiple results :
function testDeleteSerie(){
var calId = "[email protected]";
var cal = CalendarApp.getCalendarById(calId);
var date = new Date('2/22/2014/');
var events = cal.getEventsForDay(date, {search: 'test event'});
for(var n in events){
var eventId = events[n].getId();
var eventSerie = cal.getEventSeriesById(eventId);
eventSerie.deleteEventSeries();
}
}
Note also that there is a nice tool to remove duplicates in calendars (among other things this tool can do ;) that I developed using Romain Vialard Library, feel free to have a look to it on his webSite
Upvotes: 1