function ColorEvents() { var today = new Date(); var nextweek = new Date(); nextweek.setDate(nextweek.getDate() + 7); Logger.log(today + " " + nextweek); 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, nextweek); for (var j=0; j<events.length; j++) { var e = events[j]; var title = e.getTitle(); if (title[0] == "[") { e.setColor(CalendarApp.EventColor.CYAN); } if (title[0] == "!") { e.setColor(CalendarApp.EventColor.RED); } if (title[0] == '#') { e.setColor(CalendarApp.EventColor.GREEN); } } }
}
function ColorEvents() {
var today = new Date();
var nextweek = new Date();
nextweek.setDate(nextweek.getDate() + 7);
Logger.log(today + " " + nextweek);
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, nextweek);
for (var j=0; j<events.length; j++) {
var e = events[j];
var title = e.getTitle();
if (title[0-5] == "EDP") {
e.setColor(CalendarApp.EventColor.PALE_RED);
}
if (title[0-1] == "Ro" ) {
e.setColor(CalendarApp.EventColor.PALE_BLUE);
}
if (title[0-4] == "Sbux") {
e.setColor(CalendarApp.EventColor.GREEN);
}
if (title[0-4] == "Stud") {
e.setColor(CalendarApp.EventColor.YELLOW)
}
if (title[0-4] == "Keys") {
e.setColor(CalendarApp.EventColor.YELLOW)
}
}
}
}
Your are checking a position in the array title (title[0-1]) which in fact is position -1.
Or in case title[0-4] it is -4.
You should get de substring from title[0] to test against.
Syntax: string.substr(start, length)
Example:
var str = "Hello world!";
var res = str.substr(1, 4);
// res is now ello
For better explaination : https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/substring
Best regards
Cor van Dooren
The Netherlands
--
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/d879cb49-eb23-4424-b79c-4dabcf5a185eo%40googlegroups.com.