Unable to assign calendar ID iteratively to extract events from google calendar












0














I have been trying to create a working script to extract events from different people calendar. Access is available to read the events.



I have the IDs in a different sheet("Cals2Extract") in the range A2: B4 Column Header A(Cal_ID) and B(Active).



While I'm able to extract events from the first name in the column A2, I'm unable to iterate through the second and third name in column A (A3, A4....).



Extracted events are written in a different sheet (EventCal).



Sample Sheet



Any help is appreciated.



function Get(){

var ss=SpreadsheetApp.openById("ID of the sheet")
var sheet=ss.getSheetByName("Cals2Extract");
var sheetArr=sheet.getDataRange().getValues();
var range = sheet.getRange(1, 1, 1, sheet.getMaxColumns());
var values = range.getValues();
var ColIndexmap = {};
var mycal="";
var cal="";

Logger.log(sheet);

Logger.log (sheetArr);

for (var row in values) {
for (var col in values[row]) {
ColIndexmap[values[row][col]]=parseInt(col);
}}

for(var i=1;i<sheetArr.length;i++){
mycal ="";
cal ="";

Logger.log(sheetArr.length);

Logger.log(i);

mycal=sheetArr[i][ColIndexmap["Cal_ID"]];

Logger.log(mycal);

cal = CalendarApp.getCalendarById(mycal);

Logger.log(cal);

if(sheetArr[i][ColIndexmap["Active"]] != ""){


var events = cal.getEvents(new Date("November 1, 2018 00:00:00 CST"), new
Date("November 14, 2018 23:59:59 CST"), {search: ''});


var sheet1 = ss.getSheetByName("EventCal");

sheet1.clearContents();

Logger.log(sheet1);


// Create a header record on the current spreadsheet in cells A1:N1 - Match the number of entries in the "header=" to the last parameter
// of the getRange entry below



var header = [["Calendar Address", "Event Title", "Event Description", 
"Event Location", "Event Start", "Event End", "Calculated Duration",
"Visibility", "Date Created", "Last Updated", "MyStatus", "Created By", "All
Day Event", "Recurring Event"]]
var range = sheet1.getRange(1,1,1,14);
range.setValues(header);


// Loop through all calendar events found and write them out starting on calulated ROW 2 (i+2)



for (var i=0;i<events.length;i++) {
var row=i+2;
var myformula_placeholder = '';

var details=[[mycal,events[i].getTitle(), events[i].getDescription(),
events[i].getLocation(), events[i].getStartTime(), events[i].getEndTime(),
myformula_placeholder, ('' + events[i].getVisibility()),
events[i].getDateCreated(), events[i].getLastUpdated(),
events[i].getMyStatus(), events[i].getCreators(), events[i].isAllDayEvent(),
events[i].isRecurringEvent()]];
var range=sheet1.getRange(row,1,1,14);
range.setValues(details);

var cell=sheet1.getRange(row,7);
cell.setFormula('=(HOUR(F' +row+ ')+(MINUTE(F' +row+ ')/60))-(HOUR(E' +row+
')+(MINUTE(E' +row+ ')/60))');
cell.setNumberFormat('.00');

}
}
}
SpreadsheetApp.flush();
}









share|improve this question




















  • 1




    In order to understand correctly your situation, can you add more information? 1. About I'm unable to iterate through the second and third name in column A (A3, A4....)., does an error occur or ? Can you explain the detail of this? 2. Can you provide a sample spreadsheet? Of course, please remove your personal information. I think that these will help users think of your solution.
    – Tanaike
    Nov 19 '18 at 22:56










  • 1. No error occurs: I'm trying to assign calendar ID dynamically to my variable var mycal; only the first ID in A1 gets extracted. Ideally I want the next ID in A2 to get assigned to mycal and get the events extracted until the list ends in column A 2. Edited the question to include Sample sheet. I have included dummy calendar ID for testing purpose which can be replaced with your ID to test.
    – Mr Rj
    Nov 20 '18 at 11:43












  • Thank you for your response. I saw the sample spreadsheet. In your script, it seems that mycal=sheetArr[i][ColIndexmap["Cal_ID"]]; can have the values from "A2" to "A4". So I couldn't understand about your issue. Can you explain the detail? If I had misunderstood your reply, please tell me.
    – Tanaike
    Nov 20 '18 at 22:15










  • The whole code runs only for the first value i.e. A2 and doesn't loop for other values
    – Mr Rj
    Nov 21 '18 at 9:21












  • Unfortunately, I cannot replicate your situation. mycal=sheetArr[i][ColIndexmap["Cal_ID"]]; of your sample script can have the values from "A2" to "A4". If I misunderstand your issue, please tell me.
    – Tanaike
    Nov 21 '18 at 23:19
















0














I have been trying to create a working script to extract events from different people calendar. Access is available to read the events.



I have the IDs in a different sheet("Cals2Extract") in the range A2: B4 Column Header A(Cal_ID) and B(Active).



While I'm able to extract events from the first name in the column A2, I'm unable to iterate through the second and third name in column A (A3, A4....).



Extracted events are written in a different sheet (EventCal).



Sample Sheet



Any help is appreciated.



function Get(){

var ss=SpreadsheetApp.openById("ID of the sheet")
var sheet=ss.getSheetByName("Cals2Extract");
var sheetArr=sheet.getDataRange().getValues();
var range = sheet.getRange(1, 1, 1, sheet.getMaxColumns());
var values = range.getValues();
var ColIndexmap = {};
var mycal="";
var cal="";

Logger.log(sheet);

Logger.log (sheetArr);

for (var row in values) {
for (var col in values[row]) {
ColIndexmap[values[row][col]]=parseInt(col);
}}

for(var i=1;i<sheetArr.length;i++){
mycal ="";
cal ="";

Logger.log(sheetArr.length);

Logger.log(i);

mycal=sheetArr[i][ColIndexmap["Cal_ID"]];

Logger.log(mycal);

cal = CalendarApp.getCalendarById(mycal);

Logger.log(cal);

if(sheetArr[i][ColIndexmap["Active"]] != ""){


var events = cal.getEvents(new Date("November 1, 2018 00:00:00 CST"), new
Date("November 14, 2018 23:59:59 CST"), {search: ''});


var sheet1 = ss.getSheetByName("EventCal");

sheet1.clearContents();

Logger.log(sheet1);


// Create a header record on the current spreadsheet in cells A1:N1 - Match the number of entries in the "header=" to the last parameter
// of the getRange entry below



var header = [["Calendar Address", "Event Title", "Event Description", 
"Event Location", "Event Start", "Event End", "Calculated Duration",
"Visibility", "Date Created", "Last Updated", "MyStatus", "Created By", "All
Day Event", "Recurring Event"]]
var range = sheet1.getRange(1,1,1,14);
range.setValues(header);


// Loop through all calendar events found and write them out starting on calulated ROW 2 (i+2)



for (var i=0;i<events.length;i++) {
var row=i+2;
var myformula_placeholder = '';

var details=[[mycal,events[i].getTitle(), events[i].getDescription(),
events[i].getLocation(), events[i].getStartTime(), events[i].getEndTime(),
myformula_placeholder, ('' + events[i].getVisibility()),
events[i].getDateCreated(), events[i].getLastUpdated(),
events[i].getMyStatus(), events[i].getCreators(), events[i].isAllDayEvent(),
events[i].isRecurringEvent()]];
var range=sheet1.getRange(row,1,1,14);
range.setValues(details);

var cell=sheet1.getRange(row,7);
cell.setFormula('=(HOUR(F' +row+ ')+(MINUTE(F' +row+ ')/60))-(HOUR(E' +row+
')+(MINUTE(E' +row+ ')/60))');
cell.setNumberFormat('.00');

}
}
}
SpreadsheetApp.flush();
}









share|improve this question




















  • 1




    In order to understand correctly your situation, can you add more information? 1. About I'm unable to iterate through the second and third name in column A (A3, A4....)., does an error occur or ? Can you explain the detail of this? 2. Can you provide a sample spreadsheet? Of course, please remove your personal information. I think that these will help users think of your solution.
    – Tanaike
    Nov 19 '18 at 22:56










  • 1. No error occurs: I'm trying to assign calendar ID dynamically to my variable var mycal; only the first ID in A1 gets extracted. Ideally I want the next ID in A2 to get assigned to mycal and get the events extracted until the list ends in column A 2. Edited the question to include Sample sheet. I have included dummy calendar ID for testing purpose which can be replaced with your ID to test.
    – Mr Rj
    Nov 20 '18 at 11:43












  • Thank you for your response. I saw the sample spreadsheet. In your script, it seems that mycal=sheetArr[i][ColIndexmap["Cal_ID"]]; can have the values from "A2" to "A4". So I couldn't understand about your issue. Can you explain the detail? If I had misunderstood your reply, please tell me.
    – Tanaike
    Nov 20 '18 at 22:15










  • The whole code runs only for the first value i.e. A2 and doesn't loop for other values
    – Mr Rj
    Nov 21 '18 at 9:21












  • Unfortunately, I cannot replicate your situation. mycal=sheetArr[i][ColIndexmap["Cal_ID"]]; of your sample script can have the values from "A2" to "A4". If I misunderstand your issue, please tell me.
    – Tanaike
    Nov 21 '18 at 23:19














0












0








0







I have been trying to create a working script to extract events from different people calendar. Access is available to read the events.



I have the IDs in a different sheet("Cals2Extract") in the range A2: B4 Column Header A(Cal_ID) and B(Active).



While I'm able to extract events from the first name in the column A2, I'm unable to iterate through the second and third name in column A (A3, A4....).



Extracted events are written in a different sheet (EventCal).



Sample Sheet



Any help is appreciated.



function Get(){

var ss=SpreadsheetApp.openById("ID of the sheet")
var sheet=ss.getSheetByName("Cals2Extract");
var sheetArr=sheet.getDataRange().getValues();
var range = sheet.getRange(1, 1, 1, sheet.getMaxColumns());
var values = range.getValues();
var ColIndexmap = {};
var mycal="";
var cal="";

Logger.log(sheet);

Logger.log (sheetArr);

for (var row in values) {
for (var col in values[row]) {
ColIndexmap[values[row][col]]=parseInt(col);
}}

for(var i=1;i<sheetArr.length;i++){
mycal ="";
cal ="";

Logger.log(sheetArr.length);

Logger.log(i);

mycal=sheetArr[i][ColIndexmap["Cal_ID"]];

Logger.log(mycal);

cal = CalendarApp.getCalendarById(mycal);

Logger.log(cal);

if(sheetArr[i][ColIndexmap["Active"]] != ""){


var events = cal.getEvents(new Date("November 1, 2018 00:00:00 CST"), new
Date("November 14, 2018 23:59:59 CST"), {search: ''});


var sheet1 = ss.getSheetByName("EventCal");

sheet1.clearContents();

Logger.log(sheet1);


// Create a header record on the current spreadsheet in cells A1:N1 - Match the number of entries in the "header=" to the last parameter
// of the getRange entry below



var header = [["Calendar Address", "Event Title", "Event Description", 
"Event Location", "Event Start", "Event End", "Calculated Duration",
"Visibility", "Date Created", "Last Updated", "MyStatus", "Created By", "All
Day Event", "Recurring Event"]]
var range = sheet1.getRange(1,1,1,14);
range.setValues(header);


// Loop through all calendar events found and write them out starting on calulated ROW 2 (i+2)



for (var i=0;i<events.length;i++) {
var row=i+2;
var myformula_placeholder = '';

var details=[[mycal,events[i].getTitle(), events[i].getDescription(),
events[i].getLocation(), events[i].getStartTime(), events[i].getEndTime(),
myformula_placeholder, ('' + events[i].getVisibility()),
events[i].getDateCreated(), events[i].getLastUpdated(),
events[i].getMyStatus(), events[i].getCreators(), events[i].isAllDayEvent(),
events[i].isRecurringEvent()]];
var range=sheet1.getRange(row,1,1,14);
range.setValues(details);

var cell=sheet1.getRange(row,7);
cell.setFormula('=(HOUR(F' +row+ ')+(MINUTE(F' +row+ ')/60))-(HOUR(E' +row+
')+(MINUTE(E' +row+ ')/60))');
cell.setNumberFormat('.00');

}
}
}
SpreadsheetApp.flush();
}









share|improve this question















I have been trying to create a working script to extract events from different people calendar. Access is available to read the events.



I have the IDs in a different sheet("Cals2Extract") in the range A2: B4 Column Header A(Cal_ID) and B(Active).



While I'm able to extract events from the first name in the column A2, I'm unable to iterate through the second and third name in column A (A3, A4....).



Extracted events are written in a different sheet (EventCal).



Sample Sheet



Any help is appreciated.



function Get(){

var ss=SpreadsheetApp.openById("ID of the sheet")
var sheet=ss.getSheetByName("Cals2Extract");
var sheetArr=sheet.getDataRange().getValues();
var range = sheet.getRange(1, 1, 1, sheet.getMaxColumns());
var values = range.getValues();
var ColIndexmap = {};
var mycal="";
var cal="";

Logger.log(sheet);

Logger.log (sheetArr);

for (var row in values) {
for (var col in values[row]) {
ColIndexmap[values[row][col]]=parseInt(col);
}}

for(var i=1;i<sheetArr.length;i++){
mycal ="";
cal ="";

Logger.log(sheetArr.length);

Logger.log(i);

mycal=sheetArr[i][ColIndexmap["Cal_ID"]];

Logger.log(mycal);

cal = CalendarApp.getCalendarById(mycal);

Logger.log(cal);

if(sheetArr[i][ColIndexmap["Active"]] != ""){


var events = cal.getEvents(new Date("November 1, 2018 00:00:00 CST"), new
Date("November 14, 2018 23:59:59 CST"), {search: ''});


var sheet1 = ss.getSheetByName("EventCal");

sheet1.clearContents();

Logger.log(sheet1);


// Create a header record on the current spreadsheet in cells A1:N1 - Match the number of entries in the "header=" to the last parameter
// of the getRange entry below



var header = [["Calendar Address", "Event Title", "Event Description", 
"Event Location", "Event Start", "Event End", "Calculated Duration",
"Visibility", "Date Created", "Last Updated", "MyStatus", "Created By", "All
Day Event", "Recurring Event"]]
var range = sheet1.getRange(1,1,1,14);
range.setValues(header);


// Loop through all calendar events found and write them out starting on calulated ROW 2 (i+2)



for (var i=0;i<events.length;i++) {
var row=i+2;
var myformula_placeholder = '';

var details=[[mycal,events[i].getTitle(), events[i].getDescription(),
events[i].getLocation(), events[i].getStartTime(), events[i].getEndTime(),
myformula_placeholder, ('' + events[i].getVisibility()),
events[i].getDateCreated(), events[i].getLastUpdated(),
events[i].getMyStatus(), events[i].getCreators(), events[i].isAllDayEvent(),
events[i].isRecurringEvent()]];
var range=sheet1.getRange(row,1,1,14);
range.setValues(details);

var cell=sheet1.getRange(row,7);
cell.setFormula('=(HOUR(F' +row+ ')+(MINUTE(F' +row+ ')/60))-(HOUR(E' +row+
')+(MINUTE(E' +row+ ')/60))');
cell.setNumberFormat('.00');

}
}
}
SpreadsheetApp.flush();
}






events calendar google-calendar-api extract spreadsheet






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 20 '18 at 13:19









E_net4 wishes happy holidays

11.9k63468




11.9k63468










asked Nov 19 '18 at 17:06









Mr Rj

146




146








  • 1




    In order to understand correctly your situation, can you add more information? 1. About I'm unable to iterate through the second and third name in column A (A3, A4....)., does an error occur or ? Can you explain the detail of this? 2. Can you provide a sample spreadsheet? Of course, please remove your personal information. I think that these will help users think of your solution.
    – Tanaike
    Nov 19 '18 at 22:56










  • 1. No error occurs: I'm trying to assign calendar ID dynamically to my variable var mycal; only the first ID in A1 gets extracted. Ideally I want the next ID in A2 to get assigned to mycal and get the events extracted until the list ends in column A 2. Edited the question to include Sample sheet. I have included dummy calendar ID for testing purpose which can be replaced with your ID to test.
    – Mr Rj
    Nov 20 '18 at 11:43












  • Thank you for your response. I saw the sample spreadsheet. In your script, it seems that mycal=sheetArr[i][ColIndexmap["Cal_ID"]]; can have the values from "A2" to "A4". So I couldn't understand about your issue. Can you explain the detail? If I had misunderstood your reply, please tell me.
    – Tanaike
    Nov 20 '18 at 22:15










  • The whole code runs only for the first value i.e. A2 and doesn't loop for other values
    – Mr Rj
    Nov 21 '18 at 9:21












  • Unfortunately, I cannot replicate your situation. mycal=sheetArr[i][ColIndexmap["Cal_ID"]]; of your sample script can have the values from "A2" to "A4". If I misunderstand your issue, please tell me.
    – Tanaike
    Nov 21 '18 at 23:19














  • 1




    In order to understand correctly your situation, can you add more information? 1. About I'm unable to iterate through the second and third name in column A (A3, A4....)., does an error occur or ? Can you explain the detail of this? 2. Can you provide a sample spreadsheet? Of course, please remove your personal information. I think that these will help users think of your solution.
    – Tanaike
    Nov 19 '18 at 22:56










  • 1. No error occurs: I'm trying to assign calendar ID dynamically to my variable var mycal; only the first ID in A1 gets extracted. Ideally I want the next ID in A2 to get assigned to mycal and get the events extracted until the list ends in column A 2. Edited the question to include Sample sheet. I have included dummy calendar ID for testing purpose which can be replaced with your ID to test.
    – Mr Rj
    Nov 20 '18 at 11:43












  • Thank you for your response. I saw the sample spreadsheet. In your script, it seems that mycal=sheetArr[i][ColIndexmap["Cal_ID"]]; can have the values from "A2" to "A4". So I couldn't understand about your issue. Can you explain the detail? If I had misunderstood your reply, please tell me.
    – Tanaike
    Nov 20 '18 at 22:15










  • The whole code runs only for the first value i.e. A2 and doesn't loop for other values
    – Mr Rj
    Nov 21 '18 at 9:21












  • Unfortunately, I cannot replicate your situation. mycal=sheetArr[i][ColIndexmap["Cal_ID"]]; of your sample script can have the values from "A2" to "A4". If I misunderstand your issue, please tell me.
    – Tanaike
    Nov 21 '18 at 23:19








1




1




In order to understand correctly your situation, can you add more information? 1. About I'm unable to iterate through the second and third name in column A (A3, A4....)., does an error occur or ? Can you explain the detail of this? 2. Can you provide a sample spreadsheet? Of course, please remove your personal information. I think that these will help users think of your solution.
– Tanaike
Nov 19 '18 at 22:56




In order to understand correctly your situation, can you add more information? 1. About I'm unable to iterate through the second and third name in column A (A3, A4....)., does an error occur or ? Can you explain the detail of this? 2. Can you provide a sample spreadsheet? Of course, please remove your personal information. I think that these will help users think of your solution.
– Tanaike
Nov 19 '18 at 22:56












1. No error occurs: I'm trying to assign calendar ID dynamically to my variable var mycal; only the first ID in A1 gets extracted. Ideally I want the next ID in A2 to get assigned to mycal and get the events extracted until the list ends in column A 2. Edited the question to include Sample sheet. I have included dummy calendar ID for testing purpose which can be replaced with your ID to test.
– Mr Rj
Nov 20 '18 at 11:43






1. No error occurs: I'm trying to assign calendar ID dynamically to my variable var mycal; only the first ID in A1 gets extracted. Ideally I want the next ID in A2 to get assigned to mycal and get the events extracted until the list ends in column A 2. Edited the question to include Sample sheet. I have included dummy calendar ID for testing purpose which can be replaced with your ID to test.
– Mr Rj
Nov 20 '18 at 11:43














Thank you for your response. I saw the sample spreadsheet. In your script, it seems that mycal=sheetArr[i][ColIndexmap["Cal_ID"]]; can have the values from "A2" to "A4". So I couldn't understand about your issue. Can you explain the detail? If I had misunderstood your reply, please tell me.
– Tanaike
Nov 20 '18 at 22:15




Thank you for your response. I saw the sample spreadsheet. In your script, it seems that mycal=sheetArr[i][ColIndexmap["Cal_ID"]]; can have the values from "A2" to "A4". So I couldn't understand about your issue. Can you explain the detail? If I had misunderstood your reply, please tell me.
– Tanaike
Nov 20 '18 at 22:15












The whole code runs only for the first value i.e. A2 and doesn't loop for other values
– Mr Rj
Nov 21 '18 at 9:21






The whole code runs only for the first value i.e. A2 and doesn't loop for other values
– Mr Rj
Nov 21 '18 at 9:21














Unfortunately, I cannot replicate your situation. mycal=sheetArr[i][ColIndexmap["Cal_ID"]]; of your sample script can have the values from "A2" to "A4". If I misunderstand your issue, please tell me.
– Tanaike
Nov 21 '18 at 23:19




Unfortunately, I cannot replicate your situation. mycal=sheetArr[i][ColIndexmap["Cal_ID"]]; of your sample script can have the values from "A2" to "A4". If I misunderstand your issue, please tell me.
– Tanaike
Nov 21 '18 at 23:19












0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53379516%2funable-to-assign-calendar-id-iteratively-to-extract-events-from-google-calendar%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53379516%2funable-to-assign-calendar-id-iteratively-to-extract-events-from-google-calendar%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

MongoDB - Not Authorized To Execute Command

How to fix TextFormField cause rebuild widget in Flutter

in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith