Copy events from shared external calendar to my own calendar

134 views
Skip to first unread message

CAROLE CLOUET

unread,
Oct 27, 2022, 9:37:00 AM10/27/22
to Google Apps Script Community
Hi,
I am a total newbie in scripting

Here is my piece of code for copying all events in the next 12 months from a shared external calendar to my own calendar.

I always get a "ReferenceError: Title is not defined" on line 14

Please Help ! :(

function copyLastDayEvents() {
  var source = CalendarApp.getCalendarById('IDexternalCalendar'); 
  var target = CalendarApp.getCalendarById('IDownCalendar'); 
  var today = new Date();
  var maxDate = new Date();
  maxDate.setMonth(maxDate.getMonth() + 12);
  var events = source.getEvents(today, maxDate);
  for (var i = 0; i < events.length; i++) { 
    var event = events[i];
    var title = event.getTitle();
    var StartTime = event.getStartTime();
    var EndTime = event.getEndTime();
    }
  target.createEvent(Title,StartTime,EndTime);
          Utilities.sleep(100);    
  }

Dave Roeser

unread,
Oct 27, 2022, 10:59:32 AM10/27/22
to google-apps-sc...@googlegroups.com
You never defined Title...you have  var title = event.getTitle();

Change Title to title in the createEvent statement and give it a go.

Take care,
Dave 

--
You received this message because you are subscribed to the Google Groups "Google Apps Script Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-script-c...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-script-community/4117124d-7060-40b7-a3a0-3b77e40f3c2an%40googlegroups.com.

CAROLE CLOUET

unread,
Oct 28, 2022, 6:06:55 AM10/28/22
to google-apps-sc...@googlegroups.com
Hi, 
Thanks for your help !!
then I got another issue... it actually copies only the events happening in 12 months time but not those in less time from now (11 month, 10 months, etc...)

What I actually am looking to do is automatically updating my personal calendar from the shared one as soon as an event is added, updated or cancelled...

I think I am getting something wrong here... :(

But thanks again !! 

You received this message because you are subscribed to a topic in the Google Groups "Google Apps Script Community" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/google-apps-script-community/bgHz27qTPTM/unsubscribe.
To unsubscribe from this group and all its topics, send an email to google-apps-script-c...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-script-community/CADO6D4Nf9y_m8zMCkHAwLADdJDYYGDuPEoqPJybkKtgbqQJHHg%40mail.gmail.com.

Andrew Roberts

unread,
Oct 28, 2022, 9:34:10 AM10/28/22
to google-apps-sc...@googlegroups.com
That's because you are using "today" as the start date. Set a "startDate" in the same way as maxDate is derived.

CAROLE CLOUET

unread,
Oct 28, 2022, 9:49:52 AM10/28/22
to google-apps-sc...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages