Hi there I am trying to modify a script that syncs google calendars with google sheets. Both from Calendar to Sheet and from Sheet to calendar.
Currently the calendar ID is manually input on this line in the google code:
var calendarId = '(calendarid@group.calendar.google.com';
This is from the script by Dave Par https://github.com/Davepar/gcalendarsync
I have modified the menu that is displayed as follows:
var ui = SpreadsheetApp.getUi();
var subMenu = SpreadsheetApp.getUi().createMenu('Update to Calendar')
.addItem('Update to Calendar', 'syncToCalendar')
var topMenu = SpreadsheetApp.getUi().createMenu('Calendar Sync')
.addItem('Update from Calendar', 'syncFromCalendar')
.addSubMenu(subMenu);
topMenu.addToUi();
}
What im trying to do is get each of the two functions SyncToCalendar and SyncFromCalendar in the menu to be able to have a submenu as a drop down list populated of all my calendars using the below function
https://developers.google.com/calendar/v3/reference/calendarList/list#examples
var calendars, pageToken;
do {
calendars = Calendar.CalendarList.list({
maxResults: 100,
pageToken: pageToken
});
if (calendars.items && calendars.items.length > 0) {
for (var i = 0; i < calendars.items.length; i++) {
var calendar = calendars.items[i];
Logger.log('%s (ID: %s)', calendar.summary, calendar.id);
}
} else {
Logger.log('No calendars found.');
}
pageToken = calendars.nextPageToken;
} while (pageToken);
}
so essentially being able to select a specific calendar to run Function SyncTocalendar and function SyncFromCalendar on.
Any help to achieve this would be much appreciated.
I have seen a topic where this has been done on a cell where you just change an id, so im hoping maybe this cript can be modified to have the calendar names in a sub menu drop down instead?