Finally I was able to create function that will automatically update event in a calendar. I tested it and it worked perfectly; it will add new event in the calendar, and when user edits it, it will delete previous event and create new event along with new ID.
The next day however, when I tested it again, it doesn't work, I checked all functions in the code.gs, only this function has problem.
function updateCalendar(request) {
var sheet = SpreadsheetApp.getActiveSheet();
var lastRow = sheet.getLastRow();
var range = sheet.getRange(2,1,lastRow,13);
var values = range.getDisplayValues();
var calendar = CalendarApp.getCalendarById('XXXXXXXXXXXXXXXXXXX@group.calendar.google.com');
var numValues = 0;
for (var i = 0; i < values.length; i++) {
if (values[i][0].length > 0) {
if (values[i][12] == undefined) {
var newEvent = calendar.createEvent("booked", request.date, request.endTime);
var newEventId = newEvent.getId().split('@')[0];
//mark as entered, enter ID
sheet.getRange(i+2,13).setValue('y');
sheet.getRange(i+2,12).setValue(newEventId);
}
else if (values[i][12] == 'y') {
var eventEditId = calendar.getEventSeriesById(values[i][11]);
eventEditId.deleteEventSeries();
var newEvent = calendar.createEvent("booked", request.date, request.endTime);
var newEventId = newEvent.getId().split('@')[0];;
//mark as entered, enter ID
sheet.getRange(i+2,13).setValue('y');
sheet.getRange(i+2,12).setValue(newEventId);
}
}
numValues++;
}
};
I also checked the calendar settings and stuffs, and made sure that I was logged into the admin account. Any help is greatly appreciated, thanks in advance.
I simply changed "undefined" to simply a null string ' ', it works again. But again, for some reason i am curious why it worked last time with "undefined" command
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.