Estou tentando criar uma planilha do Google que eu possa usar para agendar um calendário de manutenção de oficina.
Eu segui o tutorial abaixo, mas estou entendendo algo errado. Espero que alguém consiga identificar o erro facilmente.
https://www.youtube.com/watch?v=fAfomDR0pe4&list=PL3ooKofg5LEr7yYPz7DyReKrAhhBecfUv
Este erro aparece e tentei descobrir o motivo, mas não consegui. Formatei a hora de início e a hora de término para "data e hora" e tentei remover todas as células, mantendo apenas o que estou inserindo. Acho que posso ter inserido os intervalos incorretamente? Não tenho certeza...
Exceção: Os parâmetros (String,String,null,(class)) não correspondem à assinatura do método para CalendarApp.Calendar.createEvent.
Código de script abaixo:
let calendarId = '[email protected]'; // 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', ''];
}
Imagem da Planilha Google: