Thomas Wippler
Thomas Wippler

Reputation: 13

Change color of an individual Calendar Event in Google Calendar using Apps Script

I am trying to change the color of some individual calendar events that start with the word "Klausur". There seems to be a problem with the setColor() method. But I cant figure out why. If I call the method on the entire calendar it dose work but on individual events it dose not.

function changeKlausurColor() {
    var now = new Date();
    var start = new Date(now.getTime() - (604800 * 1000 * 52));
    var end = new Date(now.getTime() + (604800 * 1000 * 52));
    var srcCal = CalendarApp.getCalendarById("CalendarID");
    var events = srcCal.getEvents(start, end);
    for (var i in events) {
        if (events[i].getTitle().indexOf("Klausur") == 0) {
            var color = events[i].setColor("#0D7813");
        }
    }
}

Upvotes: 0

Views: 2608

Answers (1)

Tanaike
Tanaike

Reputation: 201493

You can select the event color from Enum EventColor. When this is reflected to your script, please modify as follows.

From :

var color = events[i].setColor("#0D7813");

To :

var color = events[i].setColor(CalendarApp.EventColor.GREEN);

References :

Upvotes: 2

Related Questions