[Solved] Google calendar sync with google spreadsheet


The calendar id is declared on line 8

var calendarId = 'bora-bora.dk_is0cr9ibe4thrs4mkqghvudrrk@group.calendar.google.com';

It is called by two functions:
1 = syncFromCalendar on line 223. Synchronize from calendar to spreadsheet.

var calendar = CalendarApp.getCalendarById(calendarId);

2 = syncToCalendar on line 307. Synchronize from spreadsheet to calendar.

var calendar = CalendarApp.getCalendarById(calendarId);

The goal is to call the calendar ID programmatically to source the value from Cell B1 of the Data Sheet.
To do this, i) the variable should be removed, ii) add/insert new code to source the new value for the calendar ID, and iii) make adjustments to the functions that call for the value of the calendar ID.

Action:

1 – comment out Line 8
2 – Insert the following code at Line 9

// Get the calendar code from Sheet "Data", cell B1
function getcalendarId() {
  var spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
  var sheet = spreadsheet.getSheetByName("Data");
  var calrange = sheet.getRange("B1");
  var calid =calrange.getValue();
  return calid;
}

3 – Locate function = syncFromCalendar
3.1 – Comment out this line

var calendar = CalendarApp.getCalendarById(calendarId);

3.2 Insert/add these three lines above the commented line

// Get the calendar ID
var calidFrom = getcalendarId();
var calendar = CalendarApp.getCalendarById(calidFrom);

4 – Locate function = syncToCalendar
4.1 Comment out this line

var calendar = CalendarApp.getCalendarById(calendarId);

4.2 Insert/add these three lines above the commented line

// Get the calendar ID
var calidTo = getcalendarId();
var calendar = CalendarApp.getCalendarById(calidTo);

1

solved Google calendar sync with google spreadsheet