This javascript is something I configured to be used for Google Calendar. It automatically makes your private invites, private and colour coded. This works perfectly.
At the sametime I want to colourcode all the invites I get from external companies/partners. This I can't seem to make work. I tried .includes(), but those require exact strings which I don't have. The current code pretty much marks all events right now instead of the intended external email domains.
function ColorEvents() {
var today = new Date();
var nextmonth = new Date();
nextmonth.setDate(nextmonth.getDate() + 31);
Logger.log(today + " " + nextmonth);
var calendars = CalendarApp.getAllOwnedCalendars();
Logger.log("found number of calendars: " + calendars.length);
for (var i=0; i<calendars.length; i++) {
var calendar = calendars[i];
var events = calendar.getEvents(today, nextmonth,);
for (var j=0; j<events.length; j++) {
var e = events[j];
var title = e.getTitle();
var creator = e.getCreators();
var guest = e.getGuestList();
if (!creator.indexOf(/@company.net|@partner.nl|@daughtercompany.net/)) {
e.setColor(CalendarApp.EventColor.PALE_BLUE);
}
if (creator.includes("myemail@company.net") &&!title.includes("Lunch") ) {
e.setColor(CalendarApp.EventColor.PALE_GREEN);
}
if (creator.includes("wife@gmail.com") || guest.includes("wife@gmail.com")) {
e.setColor(CalendarApp.EventColor.PALE_RED).setVisibility(CalendarApp.Visibility.PRIVATE);;
}
if (creator.includes("boyfriend@gmail.com")) {
e.setColor(CalendarApp.EventColor.PALE_RED).setVisibility(CalendarApp.Visibility.PRIVATE);
}
if (title.includes("Lunch") || (title.includes("Block"))) {
e.setColor(CalendarApp.EventColor.GRAY);
}
}
}
}