3

Im trying to use the advanced calendar service in Google Apps Script to change the colorId on a particular event in my calendar.

So far i have been able to list and get event's and the event i like. So i have the ID of the event.

function getSpecificEvent(){
  var calendarId = 'primary';
  var eventId = '7h2tbvns2oo4r5gku6ghjfjclk';
  var calEvent = Calendar.Events.get(calendarId, eventId);
  Logger.log(calEvent);
}

This is what im trying when editing the colorID, i use patch:

function setEventColor(){
  var calendarId = 'primary';
  var eventId = '7h2tbvns2oo4r5gku6ghjfjclk';
   Calendar.Events.patch(calendarId, eventId).colorId('11');
}

But then i get this error: enter image description here

Line 33 in this case is this line:

   Calendar.Events.patch(calendarId, eventId).colorId
John Smith
  • 387
  • 2
  • 8
  • 24

1 Answers1

5

This is a bit tricky... but I found how it works :

function ChangeEventColor(){
  var calendarId = 'primary';
  var eventId = 'omv°°°°°°°°°°8jbs'
  var event = Calendar.Events.get(calendarId, eventId)
  Logger.log('current color = '+event.colorId)
  event.colorId = 11
  Calendar.Events.patch(event,calendarId,eventId);
  Logger.log('new color = '+event.colorId)
}

This post (anonymous) was very helpful

Community
  • 1
  • 1
Serge insas
  • 45,904
  • 7
  • 105
  • 131