Thursday, October 28, 2010

Google Apps Script and Recurring Calendar Events

Apps Script has added support for recurring calendar events. Users can now write scripts that create, retrieve, update, and delete recurring events in calendars. We’ve also made the interface for this feature simple and easy to use. Let’s look at some examples.

The following code snippet creates a calendar event for all days that are Friday the 13th, so you can remember to avoid bad luck on those days.

var calendar = CalendarApp.getCalendarsByName("My Calendar")[0];
var fridayTheThirteenth = CalendarApp.newRecurrence();
fridayTheThirteenth.addDateExclusion(new Date())
.addDailyRule()
.onlyOnWeekday(CalendarApp.Weekday.FRIDAY)
.onlyOnMonthDay(13);
calendar.createAllDayEventSeries("Bad luck!", new Date(), fridayTheThirteenth);

The next code snippet adds an event to your calendar to remind you of election day in the United States.

var calendar = CalendarApp.getCalendarsByName("My Calendar")[0];
var usaElectionDay = CalendarApp.newRecurrence();
usaElectionDay.addDateExclusion(new Date())
.addYearlyRule()
.interval(4)
.onlyInMonth(CalendarApp.Month.NOVEMBER)
.onlyOnWeekday(CalendarApp.Weekday.TUESDAY)
.onlyOnMonthDays([2, 3, 4, 5, 6, 7, 8]);
calendar.createAllDayEventSeries("Go vote!!!", new Date(), usaElectionDay);

The interface to interact with recurring events is very straight forward and powerful. We were able to easily select all days matching the parameters Friday the 13th, and also to match all Tuesdays in each occurrence of November having a date between 2 and 8, every four years. You can quickly and easily describe dates and times of recurring events you’re looking for. For more information, please check out the release notes and updated documentation.

4 comments:

  1. I wish I knew how to script.. :( this could be useful.

    ReplyDelete
  2. I know how to script email me we can work on weekends to roll it out

    nishnet2002@gmail.com

    ReplyDelete
  3. This is not working
    it having an error message : Authorization is required to perform that action.

    ReplyDelete