How can I copy (duplicate) a calendar event into another calendar using Google Script?

后端 未结 2 546
悲&欢浪女
悲&欢浪女 2021-01-06 11:57

I have several calendars in Google Calendar. I\'m learning Google Script and would like to create a script that copies an event from one of my calendars to another with a ch

2条回答
  •  半阙折子戏
    2021-01-06 12:09

    Some code to start with:

    function myFunction() {
      var calendarSource = CalendarApp.getCalendarById("calendarID");
      var calendarDestination = CalendarApp.getCalendarById("calendarID");
      var eventToCopy = calendarSource.getEvents(new Date("July 21, 2009 EST"), new Date("July 22, 2009 EST"));
    
      //read up: https://developers.google.com/apps-script/class_recurrence
      var newRecurrence = CalendarApp.newRecurrence().addWeeklyRule().times(10);
    
      for (var i in eventToCopy){
        if (eventToCopy[i].getTitle() == "event name"){
          var newEvent = calendarDestination.createEventSeries(eventToCopy[i].getTitle(), eventToCopy[i].getStartTime(), eventToCopy[i].getEndTime(), newRecurrence);
        }
    
    }
    

    this should get you started,

提交回复
热议问题