Search code examples
google-sheetsgoogle-apps-scriptcalendar

Export to GCal from GSheet using Apps Script: Exception: Invalid argument: title


I got an error when try to create an event from GSheet data to GCal using Apps script: Exception: Invalid argument: title

The code i used:

function scheduleEvents() {
  var spreadsheet = SpreadsheetApp.getActiveSheet();
  // var calendarId = spreadsheet.getRange("").getValue();
  var eventCal = CalendarApp.getCalendarById("____");

  var workplans = spreadsheet.getRange("GE!F14:G16").getValues();

  for (x=0; x<workplans.length; x++) {
    var event = workplans[x];

    var startTime = new Date(event[0]);
    var endTime = new Date(event[1]);
    var tasks = event[2];

    eventCal.createEvent(tasks, startTime, endTime);

  }
}

Any suggestions ?


Solution

  • In your code tasks is undefined: range GE!F14:G16 has only two columns and tasks is sourced from the third column event[2].