google-apps-scriptgoogle-calendar-recurring-events

Event recurrence number as variable in event description Google App Script Calendar


I have the following code that creates an appointment that recurs 6 times. This is working nicely, however, it would be great if I could access the number of the recurrence in a variable and print that in the title as "appointment 1", "appointment 2", etc. Is this possible with the addWeeklyRule method or would it only be possible with a loop?

    var eventSeries = cal3.createEventSeries(name, startTime, endTime, CalendarApp.newRecurrence().addWeeklyRule().times(6), {
    description: descriptionText

Solution

  • Found a way to do it without a method but just got the events and changed the title. Had to add a wait step though because it couldn't find the events right after creating them.

    Utilities.sleep(5000);
    
    var untilPlanned = new Date(startTime.getTime() + (1000 * 60 * 60 * 24 * 7 * 8));
    var startPlanned = new Date(startTime.getTime() - (1000 * 60 * 60 * 12));
    //search for events 
    var eventsPlanned = cal3.getEvents(startPlanned, untilPlanned, {
        search: descriptionText
    });
    for (var k = 0; k < eventsPlanned.length; k++) {
        var sessionNo = k + 1;
        var title = Sessie: " + sessionNo + "
        eventsPlanned[k].setTitle(title);
    }