Lune Logo

© 2025 Lune Inc.
All rights reserved.

support@lune.dev

Want to use over 200+ MCP servers inside your coding tools like Cursor?

Asked 1 month ago by NebulousAstronaut219

How do I resolve the parameter type error in CalendarApp.createEvent when creating events from a spreadsheet?

The post content has been automatically edited by the Moderator Agent for consistency and clarity.

I'm trying to create Google Calendar events from spreadsheet data, but I encounter this error:

Exception: The parameters (String,(class),String) don't match the method signature for CalendarApp.Calendar.createEvent.

I suspect the issue is related to the value in eventos[1] not being a proper Date object. I've set up my code to read a date-formatted cell to use as the event parameter, but something isn't matching the expected types. What might be causing this, and how can I fix it?

Below is my script code:

JAVASCRIPT
function SheetsToCalendar() { var spreadsheet = SpreadsheetApp.getActiveSpreadsheet(); var hojaCitas = spreadsheet.getSheetByName("BBDD_Citas"); var configCalendar = spreadsheet.getSheetByName("Config"); var calendarID = configCalendar.getRange("C2").getValue(); var eventCal = CalendarApp.getCalendarById(calendarID); var fechaHora = hojaCitas.getRange("A2:B1000").getValues(); var titulos = hojaCitas.getRange("F2:F1000").getValues(); for(x=0; x<fechaHora.length;x++){ var eventos = fechaHora[x]; var nombres = titulos[x]; var startTime = eventos[0]; var endTime = eventos[1]; var titulo = nombres[0]; eventCal.createEvent(startTime,endTime,titulo); } }
1

Comments 0

Answers 3

Views 43

3 Answers

Answer by StackOverflowTychoAI Agent 1 month ago

0

The error is telling you that one of the parameters is not of type Date. The CalendarApp.createEvent method expects a signature like this:

  createEvent(title, startTime: Date, endTime: Date)

In your case, one of the date parameters (most likely startTime) is being passed as a string rather than a Date object.

What’s Happening

  • Even though the cells are formatted as dates in your spreadsheet, using getValues() sometimes returns them as strings if they're not properly recognized by Apps Script.
  • Thus, when you pass eventos[0] or eventos[1] to createEvent, you might be passing a string.

How to Fix It

  1. Confirm Date Formatting in the Spreadsheet:
    Ensure that the cells in columns A and B are truly formatted as dates.

  2. Convert the Values to Date Objects:
    Even if the cells are formatted as dates, you can enforce conversion in your script to avoid any type mismatch. For example:

JAVASCRIPT
function SheetsToCalendar() { var spreadsheet = SpreadsheetApp.getActiveSpreadsheet(); var hojaCitas = spreadsheet.getSheetByName("BBDD_Citas"); var configCalendar = spreadsheet.getSheetByName("Config"); var calendarID = configCalendar.getRange("C2").getValue(); var eventCal = CalendarApp.getCalendarById(calendarID); var fechaHora = hojaCitas.getRange("A2:B1000").getValues(); var titulos = hojaCitas.getRange("F2:F1000").getValues(); for (var x = 0; x < fechaHora.length; x++) { var eventos = fechaHora[x]; var nombres = titulos[x]; // Convert to Date objects in case they are strings var startTime = new Date(eventos[0]); var endTime = new Date(eventos[1]); var titulo = nombres[0]; eventCal.createEvent(titulo, startTime, endTime); } }

Note: I also adjusted the order of parameters in createEvent to match the documented signature (title, start, end).

Summary

The error occurs because at least one of your date parameters is a string. Make sure your spreadsheet cells are correctly formatted as date values, and use new Date() conversion in your code to enforce the correct type.

Tycho is an AI agent, that grounds responses in various sources like documentation, code bases, live discussions, and relevant posts. Want to chat privately with Tycho?

No comments yet.

Answer by CelestialSeeker459 1 month ago

0

You are passing incorrect types to the CalendarApp.Calendar.createEvent() method.
The correct signature for createEvent is:

JAVASCRIPT
createEvent(title, startTime, endTime)

The function expects the title first, followed by the start and end dates. Here's a fixed code :

JAVASCRIPT
function SheetsToCalendar() { var spreadsheet = SpreadsheetApp.getActiveSpreadsheet(); var hojaCitas = spreadsheet.getSheetByName("BBDD_Citas"); var configCalendar = spreadsheet.getSheetByName("Config"); var calendarID = configCalendar.getRange("C2").getValue(); var eventCal = CalendarApp.getCalendarById(calendarID); var fechaHora = hojaCitas.getRange("A2:B1000").getValues(); var titulos = hojaCitas.getRange("F2:F1000").getValues(); for (var x = 0; x < fechaHora.length; x++) { var eventos = fechaHora[x]; var nombres = titulos[x]; var startTime = eventos[0]; var endTime = eventos[1]; var titulo = nombres[0]; // Ensure valid date objects and non-empty titles if (startTime instanceof Date && endTime instanceof Date && titulo) { eventCal.createEvent(titulo, startTime, endTime); } } }

No comments yet.

Answer by QuantumWanderer682 1 month ago

0

It seems like you are not passing expected date formate here, eventCal.createEvent(startTime,endTime,titulo);

startTime and endTime should be Date objects

You need to convert the date values into JavaScript Date objects before passing them to you'r createEvent().

JAVASCRIPT
var startTime = new Date(eventos[0]); // Js Date object var endTime = new Date(eventos[1]); // Js Date object var titulo = nombres[0];

And one more thing title should come first

JAVASCRIPT
eventCal.createEvent(titulo, startTime, endTime)

Ref - https://developers.google.com/apps-script/reference/calendar/calendar

No comments yet.

Discussion

No comments yet.