1

I'm working on a google apps script to retrieve event data from a google sheet.

I keep getting this error: "Exception: The parameters (String,String,(class)) don't match the method signature for CalendarApp.Calendar.createAllDayEvent. (line 21, file "sheets to calendar")."

Any suggestions on the cause of the problem?

function sheets_to_calendar(){

var eventCal = CalendarApp.getCalendarById("[email protected]");
var Title = SpreadsheetApp.getActiveSheet().getRange('J1').getValue();
  
var date  = new Date(month + day + ',' + year);
var year = date.getYear();
var month = date.getMonth() + 1;  if(month.toString().length==1){var month = 
'0'+month;}
var day = date.getDate(); if(day.toString().length==1){var day = '0'+day;}
var hour = date.getHours(); if(hour.toString().length==1){var hour = '0'+hour;}
var minu = date.getMinutes(); if(minu.toString().length==1){var minu = '0'+minu;}
var seco = date.getSeconds(); if(seco.toString().length==1){var seco = '0'+seco;}
var date = year+'·'+month+'·'+day+'·'+hour+'·'+minu+'·'+seco;
Logger.log(date);

var description = SpreadsheetApp.getActiveSheet().getRange('F13').getValue();

eventCal.createAllDayEvent(Title, date, {description: "test"});
  
}

1 Answer 1

1

Issues:

  • As stated in the official documentation, createAllDayEvent(title, date, options) accepts a JavaScript date object as the second argument, not a string.
  • In your example, you are passing a string.

To create a date object in javascript you have multiple ways, but since you want to define specific month, date and year you should use this one:

var date = new Date(year, month-1, day) 

Keep in mind that the parameter month starts from 0. If you want to pass 24th of October 2020 you need to do:

var date = new Date(2020, 9, 24)

Solution:

function sheets_to_calendar(){

var eventCal = CalendarApp.getCalendarById("[email protected]");
var Title = SpreadsheetApp.getActiveSheet().getRange('J1').getValue();
var date  = new Date(year, month-1, day);
var description = SpreadsheetApp.getActiveSheet().getRange('F13').getValue();
eventCal.createAllDayEvent(Title, date, {description: description});    
}

Minimal reproducible example:

function sheets_to_calendar(){

var event = CalendarApp.getDefaultCalendar();
var date  = new Date(2020, 9, 24);
var Title = 'this is a title';
var description = 'this is a description';
event.createAllDayEvent(Title, date, {description: description});  
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.