Trouble creating new non all day events (Error: Event start time must be before event end time.)

1,121 views
Skip to first unread message

Joseph Loll

unread,
Jan 4, 2016, 7:10:49 PM1/4/16
to Google Calendar API
Sorry if this isn't a full API question. I'm not a strong programmer in any sense, so please forgive me for my ignorance.

I found some scripts to bulk enter events into Google Calendar from Google Sheets. Using this code I'm able to get All Day (using only date 2/22/2016) events to be entered into my calendar, but only if there is one event per day. If I have two dates that are the same I get a duplication error. If I enter time as seen below (2/22/2016 12:44:00) I get an Error saying (Event start time must be before event end time.) Has the API changed? I notice the example code from the API site shows (February 23, 2016 11:00:00 UTC) UTC time, which I'm not sure if is the reason.

Any guidance is appreciated!



Here's the columns of the Google Sheet:

TimestampTitleAppt. TypeStart Date and TimeEnd Date and TimeDescriptionLocationExportStatus
1/4/2016 13:46:15Joe - With John DoeInitial2/22/2016 12:44:002/22/2016 13:23:00Test DescriptionConference Room
1/4/2016 13:47:16Jane - With John DoeFollow Up
2/22/2016 12:44:002/22/2016 13:23:00Test DescriptionTeacher's Lounge

Here's the code:

function exportEvents(e)

{
   
var EVENT_EXPORTED = "EVENT_EXPORTED";
   
var calendar_name = e.parameter.calendar;
   
var Calendar = CalendarApp.getCalendarsByName(calendar_name);
   
   
var ss = SpreadsheetApp.getActiveSpreadsheet();
   
var sheet = SpreadsheetApp.getActiveSheet();
 
   
var startcolumn = 1;  // First column of data to process
   
var numcolumns = 500;   // Number of columns to process
   
var dataRange = sheet.getRange(startcolumn, 2, numcolumns, 8)   // Fetch values for each column in the Range.
   
var data = dataRange.getValues();
 
 
 
for (var i = 1; i < data.length; ++i)
 
{
   
   
var column = data[i];
   
// Timestamp is in column[1]
   
var title = column[2];        // 2nd column in spreadsheet "Title"
   
// Appt. Type is in column[3]
   
var startDate = column[4];    // 4th column in spreadsheet "Start Date and Time"
   
var endDate = column[5];      // 5th column in spreadsheet "End Date and Time"
   
var description = column[6];  // 6th column in spreadsheet "Description"
   
var location = column[7];     // 7th column in spreadsheet "Location"
   
var eventExported = column[8];// 8th column in spreadsheet "Import Status"
   
   
if (eventExported  != EVENT_EXPORTED && title != "") {  // Prevents importing duplicates
     
var cal = CalendarApp.openByName(calendar_name);
     
var options = {description: description, location: location};
      cal
.createEvent(title, new Date(startDate), new Date(endDate), options);
       
// cal.createEvent('Apollo 11 Landing', new Date('February 23, 2016 11:00:00 UTC'), new Date('February 23, 2016 12:00:00 UTC'), options);
      sheet
.getRange(startRow + i, 7).setValue(EVENT_EXPORTED);
     
Browser.msgBox("Events Exported");
     
// Make sure the cell is updated right away in case the script is interrupted
     
SpreadsheetApp.flush();  
   
}

 
}
   
var app = UiApp.getActiveApplication();
  app
.close();
 
return app;
}


Fayaz Sheriff

unread,
Oct 6, 2016, 12:49:11 AM10/6/16
to Google Calendar API
Hi Joseph , any luck i too have a similar issue.
Kindly let me know if you have resolved this issue 
Reply all
Reply to author
Forward
0 new messages