My previous question was closed, but I thought I’d post the function I worked through that gets the same result from both getCalendar...
methods for the edification of anyone else who gets confused between them. Still haven’t figured out why the examples I’ve seen posted sometimes use just .getValue
and sometimes .getValue()
, but oh well.
May the 4th be with y’all, always
function CreateEvent() {
//Retrieve information from the spreadsheet
// Make the 1st sheet active in the active spreadsheet.
var spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
SpreadsheetApp.setActiveSheet(spreadsheet.getSheets()[0]);
var sheet = spreadsheet.getSheets()[0];
//var calendarId = '';
var title = 'May the Fourth be with you';
//Retrieve the value of the calendar data from active sheet.
var calendarName = sheet.getRange("A1").getValue();
var calendarId = sheet.getRange("B1").getValue();
var startTime = sheet.getRange("C1").getValue();
var endTime = sheet.getRange("D1").getValue();
//Call CalendarApp service to open the calendar
//create event with data selected
var eventCal = CalendarApp.getCalendarById(calendarId);
eventCal.createEvent(title, startTime, endTime);
Logger.log(calendarId + " " + title + " " + startTime + " " + endTime)
//Call CalendarApp service to open the calendar
//create event with data selected
var eventCal = CalendarApp.getCalendarsByName(calendarName)[0];
var event = eventCal.createEvent(title, startTime, endTime);
Logger.log(calendarName + " " + title + " " + startTime + " " + endTime)
}