Reputation: 69
I want to copy a whole week of events into the next one using Apps-Script instead of selecting the recurrence option when creating by hand the event.
The code is shown below.
I can't figure out how to get the color of the original event and pass it to the new event.
Using e.setColor seems to work but how do I pass the color of the original event ?
function batchCopy() {
var id = '';
var cal = CalendarApp.getCalendarById(id);
var startPeriod = new Date('2019-11-04T00:00:00.000Z');
var endPeriod = new Date('2019-11-05T00:00:00.000Z');
var events = cal.getEvents(startPeriod, endPeriod);
for (var i = 0; i < events.length; i++) {
var event = events[i];
var title = event.getTitle();
var start = tweak(event.getStartTime());
var finish = tweak(event.getEndTime());
var e = cal.createEvent(title, start, finish);
//e.setColor(event.colorId.background);
Utilities.sleep(1000);
}
}
function tweak(date) {
var tweaked = new Date(date.getTime());
tweaked.setDate(date.getDate() + 7);
return tweaked;
}
Thanking you all in advance for your help.
Upvotes: 1
Views: 84
Reputation: 201493
If my understanding is correct, how about this modification?
var e = cal.createEvent(title, start, finish);
//e.setColor(event.colorId.background);
To:
var e = cal.createEvent(title, start, finish);
e.setColor(event.getColor()); // Modified
If I misunderstood your question and this was not the result you want, I apologize.
Upvotes: 1