5

Using Google Apps Script, I created a calendar that has a complex recurring event. However, I'm not able to copy that event to another calendar as a recurring event. Note: the recurring rule can't be generated or edited via the web interface.

For a real example, let's say a user wants to copy the recurring event from this publicly shared Google calendar. The event is a kind of template event for a course schedule of a Thursday course at my university.

Here are two difficulties preventing the user from copying the recurring event into another calendar the user has access to:

  • clicking on an instance of the event and saying "copy to my calendar" only copies that single event, even though the event is defined as repeating. This is not a good solution, since the user would have to do this more than 10 times to get all the events for a semester.
  • clicking on an instance of the event and then "More details" , then trying to "Copy to xxxx" under the "More actions" menu (where xxxx is a calendar the user owns) appears to work. However, when clicking Save, there is an error: "An error has occurred. Please try again later."

EDIT here's a screen shot of what the Event looks like in Google Calendar (click on event, "more details").

screen shot of details of the created event

Note that this recurring event is every Monday from the start of the semester to the end, with several exceptions. No holidays (e.g., Mon 2013-02-25), but also including Wed 2013-02-27, on which day the courses will be given as if it were a Monday (according to the university course schedule).

I repeat: the recurring events look fine in Google Calendar, but they can't be copied in there entirety to another calendar.

The GAS function that creates the calendars (not all the code is here):

function createCalendar(calendarName, courseCode, weekday, times, room, isLab) {

  Logger.log("Last day: " + LAST_TRIMESTER_DATE);
  // hack the last day so that it's not midnight but rather just before the next day, i.e., 23:59:59
  var adjustedLastDay = LAST_TRIMESTER_DATE;
  adjustedLastDay.setTime(adjustedLastDay.getTime() + (23*60*60*1000) + (59*60*1000) + (59*1000));
  Logger.log("Adjusted last day: " + adjustedLastDay);

  var eventRecurrence = CalendarApp.newRecurrence();
  eventRecurrence.addDailyRule().until(adjustedLastDay).interval(1).onlyOnWeekday(weekday);

  // get the day of the week of the first day
  var weekdayOfFirstDay = Utilities.formatDate(FIRST_TRIMESTER_DATE, LONG_TIME_ZONE, "EEEE").toUpperCase();

  // if this calendar is for a lab, exclude the first week of days
  if (isLab) {
    eventRecurrence.addDailyExclusion().times(1);
  } else {
    // it's a course, so exclude the first day if it's not the course day
    //  -- this is kind of a bug, since the "first day" of the event will always try to be created, even if it's not "onlyOnWeekday" specified
    if (weekdayOfFirstDay != weekday.toString()) {
      eventRecurrence.addDailyExclusion().times(1);
//    eventRecurrence.addDateExclusion(FIRST_TRIMESTER_DATE);
    }
  }

  // Exclude all holidays
  for (var i =  0; i 
Rubén
  • 34,714
  • 9
  • 70
  • 166
Fuhrmanator
  • 11,459
  • 6
  • 62
  • 111
  • What did you do so far with Google Apps Script? – Jacob Jan Tuinstra Jan 25 '13 at 20:53
  • @JacobJanTuinstra Do you mean, what API calls did I use to create the event? – Fuhrmanator Jan 26 '13 at 23:05
  • Yes. Will it get resolved by GAS you think? – Jacob Jan Tuinstra Jan 26 '13 at 23:15
  • The GAS is just fine to create the event. I'll try to post it when I have some time. My use case is such that users don't run any GAS to "copy" these specially fabricated events to their calendar, however. The GAS is used because of the complex nature of the recurrence. It's a rule that says, for example, the course is every Monday between the start and end of the semester, except for the list of holidays and including any other days where courses should be given as if the day was a Monday. (Yes my uni has complex calendar schedules). I suspect "copy" only works for simple recurring events. – Fuhrmanator Jan 27 '13 at 10:23
  • If you're using Google Sites, then you can create a button underneath the calendar to add all re-occurring events (easier said than done...)? – Jacob Jan Tuinstra Jan 27 '13 at 10:40
  • The work around is probably to make a button that copies all events from one calendar to another, one at a time. I can also generate the calendars brute-force, that is, using non-recurring events. I currently have a Java Applet that writes an iCal file, but the GAS code is *so much shorter and cleaner*, thanks to the recurring event API. It's sad when you hit a wall that negates the power of the API! – Fuhrmanator Jan 27 '13 at 12:41
  • What about simply inviting your students to these events using .getEventSeriesById(ID).addGuest(studentsEmail) ? I wrote a script that does that automatically... I have a class Calendar with all the course schedules and I invite all students to all events so they have their schedule in their Calendars. (the script is not public but I could share a copy with you, it works in a spreadsheet that holds the CAL Ids and records the execution logs) – Serge insas Jan 27 '13 at 21:16
  • @Sergeinsas that is a nice idea. However, my use case was to make templates for *all* courses at my university. The professors are the ones consuming the templates in Google calendars for course sites. Students generally just add the public calendars to their calendar tools (not all will use Google). The idea was to create templates to be copied by instructors, rather than generate all calendars for all courses. Of course, the IT group at my uni could find an ultimate solution like that (they have access to schedule data). I'm just a humble IT professor trying to push the technology. – Fuhrmanator Jan 28 '13 at 12:12

2 Answers2

2

This appears to be a bug in Google Calendar, in that it has trouble copying complex recurrence rules. You can report it to the team by using the "Send feedback" link under the gear icon in the Google Calendar interface.

Eric Koleda
  • 12,420
  • 1
  • 33
  • 51
  • FYI "send feedback" doesn't appear in the Google Apps Academic license version I am running, but I can report the bug using my public account. – Fuhrmanator Jan 31 '13 at 16:11
1

The other option would be to try and export the ICA and have the user import it. You might be even able to do both with some sort of link button. Here is an example of how to obtain the ica file for a google event;

http://google.com/calendar/ical/[CALENDARID]/public[or private depending]/full/[eventID].ics

This should give the code to the user and they can manually import it into their calendars. You can generate the url and send in an email to all students who sign up for the named course.

T

Tamer Ziady
  • 613
  • 1
  • 5
  • 10
  • Also, there are ways to generate the ICA via the CLI and API. You can generate and attach to a mass email....Just a work around until google fixes things. Let me know what your solution was since I am working on something similar. – Tamer Ziady Apr 26 '14 at 15:03
  • Thanks for your answer. The reason I was wanting to copy the recurring event was that the code to create the calendar in another user's account was kludgy because of permissions. With the latest API I think it's easier to do this (with permissions). I think I'll even try the Google Add-ons feature for Documents or Spreadsheets to do the same. Sharing the code and gaining permissions are handled smoothly in those features. – Fuhrmanator Apr 26 '14 at 15:16