I am trying to write a script that I can click a custom menu button and it will pull all the events scheduled on my calendar within the hours of (9:00 AM – 11:00 AM , 12:00 PM – 1:00 PM , 3:00 PM to 5:00 PM). Right now it runs by grabbing everything on my calendar for the day (including lunch) and internal meetings but I only need the events that are scheduled within the specific hours.
Also is it possible to only pull certain things from the description of a google event? For ex, the getDescription will get everything included and most of it is not needed, though there is a linkedin profile URL in the description that i do need. How can I set it so it gets the description and only retains the items I want? Here is the script I am running in App Script with the Calendar API.
var ss = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
var cal = CalendarApp.getCalendarById("[email protected]");
var today = new Date();
var dd = today.getDate();
var mm = today.getMonth(); //January is 0!
var yyyy = today.getFullYear();
var hh =
var events = cal.getEvents(new Date(yyyy, mm, dd, 0, 0, 0), new Date(yyyy, mm, dd, 23, 0, 0));
for(var i = 0;i<events.length;i++){
var title= events[i].getTitle();
var sd = events[i].getStartTime();
var loc = events[i].getLocation();
var des = events[i].getDescription();
var email = events[i].getGuestList().map(function(x) {return x.getEmail();}).join(',')
ss.getRange(i+2, 2).setValue(title);
ss.getRange(i+2, 8).setValue(loc);
ss.getRange(i+2, 9).setValue(des);
ss.getRange(i+2, 9).trimWhitespace();
ss.getRange(i+2, 1).setValue(sd);
ss.getRange(i+2, 1).setNumberFormat("mm/dd/yyyy");
ss.getRange(i+2, 7).setValue(email);
}
}
function addCandidates() {
let ui = SpreadsheetApp.getUi();
ui.createMenu('Run Code').addItem('Add New Candidates','getEvents').addToUi();
}```