Home > Blockchain >  Issues with parameters of "CalendarApp.Calendar.createEvent()" in AppScripts
Issues with parameters of "CalendarApp.Calendar.createEvent()" in AppScripts

Time:10-28

Attempting to integrate/link Google Sheets into Calendar

function updateCalendar() {
  var spreadsheet = SpreadsheetApp.getActiveSheet();
  var calendarId = spreadsheet.getRange("D3").getValue();
  var eventCal = CalendarApp.getCalendarById(calendarId);
  var data = spreadsheet.getRange("A7:D50").getValues();

  for (x=0; x<data.length-1; x  ){

  var shift = data[x];
  
  var startTime = shift[0];
  var endTime = shift[1];
  var name = shift[2];
  var notes = shift[3];
  
  eventCal.createEvent(name, startTime, endTime, notes)
}
}
Error   
Exception: The parameters (String,String,String,String) don't match the method signature for CalendarApp.Calendar.createEvent.
updateCalendar  @ Code.gs:26

Unsure why my all of my parameters for createEvent() are being returned as Strings. In my GoogleSheets, the values startTime and endTime are Date/Time values and the notes/name values are Strings. Not sure how to move forward, new to this :/

I am trying to create a sheets where I can just type in date/time/description/notes and have it automatically created Calendar Events to a specific calendar. I have tried figuring out why my values are being interpreted as strings because the spreadsheet.getRange("A7:D50").getValues(); returns either strings, date/time, or boolean values so that isn't the issue.

GoogleSheets

CodePudding user response:

Update Calendar:

function updateCalendar() {
  const ss = SpreadsheetApp.getActive();
  var sh = ss.getActiveSheet();
  var calendarId = sh.getRange("D3").getValue();
  var eventCal = CalendarApp.getCalendarById(calendarId);
  var vs = sh.getRange("A7:D50").getValues();
  vs.forEach((r, i) => {
    let startTime = new Date(r[0]);
    let endTime = new Date(r[1]);
    eventCal.createEvent(r[2], startTime, endTime, {description:r[3]})
  });
}

One question that remains is how does this keep you from creating duplicates. Answer: It doesn't.

  • Related