So I based my script on a lot of other scripts from wonderful humans around the internet. However, their script created All Day events and I only want an event to be created for an hour, so I tweaked it (unsuccessfully).
Here is my script
/**
* Adds a custom menu to the active spreadsheet, containing a single menu item
* for invoking the exportEvents() function.
* The onOpen() function, when defined, is automatically invoked whenever the
* spreadsheet is opened.
* For more information on using the Spreadsheet API, see
* https://developers.google.com/apps-script/service_spreadsheet
*/
function onOpen() {
var sheet = SpreadsheetApp.getActiveSpreadsheet();
var entries = [{
name : "Export Events",
functionName : "exportEvents"
}];
sheet.addMenu("Calendar Actions", entries);
};
/**
* Export events from spreadsheet to calendar
*/
function exportEvents() {
var sheet = SpreadsheetApp.getActiveSheet();
var headerRows = 2; // Number of rows of header info (to skip)
var range = sheet.getDataRange();
var data = range.getValues();
var calId = "shmoop.com_6bibh4i9sg0jp5qicbsl1n31ik@group.calendar.google.com";
var cal = CalendarApp.getCalendarById(calId);
for (i=0; i<data.length; i++) {
if (i < headerRows) continue; // Skip header row(s)
var row = data[i];
var date = new Date(row[0]); // First column
var project = row[1]+row[3]+row[4]; // Second column
var dueDate = new Date(row[6])
var tstart = new Date(dueDate.setTime(17,00,00,00));
var tstop = new Date(dueDate.setTime(18,00,00,00));
var id = row[15]; // Sixth column == eventId
try {
var event = cal.getEventSeriesById(id);
}
catch (e) {
// do nothing - we just want to avoid the exception when event doesn't exist
}
if (!event) {
//cal.createEvent(title, new Date("March 3, 2010 08:00:00"), new Date("March 3, 2010 09:00:00"), {description:desc,location:loc});
var newEvent = cal.createEvent(project, tstart, tstop).getId();
row[15] = newEvent; // Update the data array with event ID
} else {
event.setTitle(project);
// event.setTime(tstart, tstop); // cannot setTime on eventSeries.
// ... but we CAN set recurrence!
var recurrence = CalendarApp.newRecurrence().addDailyRule().times(1);
event.setRecurrence(recurrence, tstart, tstop);
}
debugger;
// Record all event IDs to spreadsheet
range.setValues(data);
}
}
I know the script runs because the google spreadsheet does update with an event ID everytime I run exportEvents(). But I suspect because of the tsart, tstop variable, no event is actually pushed to the calendar. Oh, also, here is an example of a row with the relevant columns on the spreadsheet:
7/10/2015 10:09:00 | Marty | wyrlwynd@mail.com | New Algebra II | Unit 11 fill-in | 380 | 7/17/2015 | In progress | | xavier@mail.com
Any help would be welcome.