I am trying to create a google sheet that I can use to schedule a workshop servicing calendar.
I have followed the below tutorial but am getting something wrong, hoping someone can easily identify the error.
https://www.youtube.com/watch?v=fAfomDR0pe4&list=PL3ooKofg5LEr7yYPz7DyReKrAhhBecfUv
This error comes up and I have tried to look up what the reason could be but am stumped. I have formatted the start time and finish time to "date time" and tried removing all cells and only keeping what I'm entering. I think it could be I have the ranges entered incorrectly? I'm not sure...
Exception: The parameters (String,String,null,(class)) don't match the method signature for CalendarApp.Calendar.createEvent.
Script code below:
let calendarId = 'westsideservicing@gmail.com'; // add your calendar id here
// if your events are coming through but the time is off, click on the gear icon to the left and make sure the time zone matches the time zone setting on your Google Calendar
// on open script menu
function onOpen() {
let ui = SpreadsheetApp.getUi();
ui.createMenu("Chur Bro").addItem("Update Calendar", "updateCalendar").addToUi();
}
// main function will irterate through data and determine if we are adding, updating or deleting an event.
function updateCalendar() {
let ss = SpreadsheetApp.getActiveSpreadsheet();
let sheet = ss.getSheetByName("Service Register");
let events = sheet.getRange(9,13,sheet.getLastRow()-1,24).getValues();
for (i = 0; i < events.length; i++) {
let event = events[i];
let returnedData;
if (event[0] != '') {
switch (event[0]) {
case 'Add':
returnedData = addEvent(event)
break;
case 'Update':
returnedData = updateEvent(event);
break;
case 'Delete':
returnedData = deleteEvent(event);
break;
}
sheet.getRange(i + 9, 21, 9, ).setValues([returnedData]);
}
}
sheet.getRange(9, 13, sheet.getLastRow()-1, 13).clearContent();
}
function addEvent(event) {
let title = event[17];
let description = event[18];
let location = event[19];
let emails = event[20];
let startTime = event[23]
let endTime = event[24]
let options = {};
if (description != '') { options['description'] = description; }
if (location != '') { options['location'] = location; }
if (emails != '') { options['guests'] = emails; }
let calendar = CalendarApp.getCalendarById(calendarId);
let id = calendar.createEvent(title, startTime, endTime, options).getId();
return ["Added", id];
}
function updateEvent(event) {
let title = event[17];
let description = event[18];
let location = event[19];
let emails = event[20];
let eventId = event[22];
let startTime = event[23];
let endTime = event[24];
let calendar = CalendarApp.getCalendarById(calendarId);
let thisEvent = calendar.getEventById(eventId);
thisEvent.setTime(startTime, endTime)
.setTitle(title)
.setDescription(description)
.setLocation(location);
if (emails != '') {
emails = emails.split(",");
emails.forEach(x => thisEvent.addGuest(x));
}
return ["Modified", eventId];
}
function deleteEvent(event) {
let eventId = event[22];
let calendar = CalendarApp.getCalendarById(calendarId);
let thisEvent = calendar.getEventById(eventId);
thisEvent.deleteEvent();
return ['Deleted', ''];
}
Image of Google Sheet:
Exception: The parameters (String,String,null,(class)) don't match the method signature for CalendarApp.Calendar.createEvent.
Based on the image of your dataset that you have provided, it seems that you've been experiencing this error because the range where it should get the values is incorrect which then results to your current script being insufficiently fulfill parameters needed for the method createEvent.
Please take a look and study about the official documentation of getRange(row, column, numRows, numColumns), as all your issues revolves within this method. Once you have understood this method it will greatly help you understand the ranges of a Spreadsheet and their indexes.
NOTE: There is also the getRange(a1Notation) method which can be easier for you to understand and implement when studying, just note that there are some limitations for thiis.
In order to get all the values of your dataset without the header, you could used this R1C1 range of:
var events = sheet.getRange(9,13,sheet.getLastRow()-8,12).getValues();
I have tried to replicate your current script and dataset to fix the issues within the ranges, Here's my working script that you can refer to and point out some of most of your issues. Feel free to play with it and adjust the ranges if there are some misplaced or correction needed.
function myFunction() {
let ss = SpreadsheetApp.getActiveSpreadsheet();
let sheet = ss.getSheetByName("Service Register");
var events = sheet.getRange(9,13,sheet.getLastRow()-8,12).getValues();
for (i = 0; i < events.length; i++) {
let event = events[i];
let returnedData;
if (event[0] != '') {
switch (event[0]) {
case 'Add':
returnedData = addEvent(event)
break;
case 'Update':
returnedData = updateEvent(event);
break;
case 'Delete':
returnedData = deleteEvent(event);
break;
}
sheet.getRange(i + 9, 21, 1, 2).setValues([returnedData]);
}
}
sheet.getRange(9, 12, sheet.getLastRow()-8, 1).clearContent();
}
function addEvent(event) {
let title = event[4];
let description = event[5];
let location = event[6];
let emails = event[7];
let startTime = event[10]
let endTime = event[11]
let options = {};
if (description != '') { options['description'] = description; }
if (location != '') { options['location'] = location; }
if (emails != '') { options['guests'] = emails; }
let calendar = CalendarApp.getCalendarById(calendarId);
let id = calendar.createEvent(title, startTime, endTime, options).getId();
console.log(id);
return ["Added", id];
}
This is the Google sheet' sample dataset that I have used within the range of M8:X11
to integrate my script.
ACTION | DATE | START TIME | END TIME | TITLE | DESCRIPTION | LOCATION | CURRENT STATUS | EVENT ID | START TIME (UTC) | END TIME (UTC) | |
---|---|---|---|---|---|---|---|---|---|---|---|
Add | 23-Apr-25 | 7:00 AM | 10:00 AM | title1 | des1 | loc1 | sample@sample.com | Added | sample@sample.com | 4/23/2025 7:00:00 | 4/23/2025 10:00:00 |
Add | 24-Apr-25 | 8:00 AM | 10:00 AM | title2 | des2 | loc2 | sample@sample.com | Added | sample@sample.com | 4/24/2025 8:00:00 | 4/24/2025 10:00:00 |
Add | 25-Apr-25 | 8:00 AM | 10:00 AM | title3 | des3 | loc3 | sample@sample.com | Added | sample@sample.com | 4/25/2025 8:00:00 | 4/25/2025 10:00:00 |
In case you plan to understand and study about the ranges and indexes of spreadsheet, you can always use these debugging methods:
console.log();
Logger.log();
It would also be easier for you to point out if you have values within the spreadsheet, and use the .getValues()
method inside of your debugging method.
Example:
var events = sheet.getRange(9,13,sheet.getLastRow()-8,12).getValues();
console.log(events); //or Logger.log(events[0]); change the element inside the events to understand indexing