I have managed to use the following code to sync my google sheets to calendar but I would also like it to automatically update the events on a calendar calendar after I edit the sheets for an existing event. Many thanks for your help.
This is the code I have now :
function createCalendarEvent(Bookings) {
const calendarId = "[email protected]";
let communitycalendar = CalendarApp.getCalendarById(calendarId);
let sheet = SpreadsheetApp.getActiveSheet();
let schedule = sheet.getDataRange().getValues();
schedule.splice(0, 2);
const events = {};
let pageToken = "";
do {
const {items, nextPageToken} = Calendar.Events.list(calendarId, {maxResults: 2500, pageToken});
if (items.length > 0) items.forEach(o => events[o.summary] = true);
pageToken = nextPageToken || "";
} while (pageToken);
schedule.forEach(function (entry) {
if (!events[entry[0]]) {
communitycalendar.createEvent(entry[0], entry[5], entry[6], {description: ''+entry[2]+','+entry[8]+'',});
}
});
}
test sheet
at the moment it creates the event but it doesnt update events if they are changed on sheets- it only adds new events.
New contributor
user26550849 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.