Question

I'm pretty new to Google-Apps-Script. Could you give an example how to use

Calendar > Recurrence > onlyOnWeeks

I want to create a daily event, but only in three specific weeks. My solution does not to work correctly. Daily events are creating but for every week.

var myrecurrence = CalendarApp.newRecurrence()
                          .addDailyRule().onlyOnWeeks([44,45,51]);
cal.createEventSeries(mytitle, startTime, endTime, myrecurrence);
Was it helpful?

Solution

The CalendarApp API behind the scenes uses the iCal specification. Per the specification, the "onlyOnWeeks" rule can only be applied with yearly rules.

More here - http://www.ietf.org/rfc/rfc2445.txt

Search for "BYWEEKNO" and find the second instance for the specific rule there.

So try this line below and I think you'll get closer. Notice the "addYearlyRule" instead of "addDailyRule"

var myrecurrence = CalendarApp.newRecurrence().addYearlyRule().onlyOnWeeks([44,45,51]);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top