-2

I've found this pretty awesome script that syncs btw google cal and google spreadsheet. Two-way sync. And it works! -> https://github.com/Davepar/gcalendarsync

Now I wan't to be able to put in the address of the calendar in a sheet named Data. In cell B1. The script should pull the address from there so that I wouldn't need to change it in the script.

Can someone figure out how to do that?
The changes would involve to define calendarId by Data!B1
And the script should only run on the Sheet

You can see sample doc here: https://docs.google.com/spreadsheets/d/1TCIIBRmshx2kmhhwrhCpg5sxO7N82tOJ7hHxWv_u-Yw/edit?usp=sharing

I made a copy of the script on the Sheet Script

2
  • Welcome to stack. First off you would need to include your code and describe any issues you are having with that code. Not link to some where else. Second we do no figure out how to solve your problems we help you with issues in your attempt to solve your own problems. Please edit your question to start with and add the code and show what you have tried to solve your problem. Commented Sep 25, 2018 at 12:44
  • I'll try once more. Tried to copy in the code but it wouldn't work. The error didn't make sense to me so I tried to solve it with this work around. Regarding the what I've tried to do ... well I've tried a lot of different stuff and none of it worked but I'll describe one of the thing. Thanks for the heads up. Commented Sep 26, 2018 at 13:40

1 Answer 1

7

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
  • 3
    There are many reasons that an answer might be voted down. But it is unhelpful to be the first to down vote and yet not comment on why. Is the answer wrong, is it incomplete, did it not answer the question, and so on? This question sat for a month with no responses. I'm neither a saint nor a martyr but if we are to try and help questioners, there is an obligation on down-voters to at least comment on what aspects of the answer inspired their vote.
    – Tedinoz
    Commented Oct 23, 2018 at 0:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.