Reputation: 491
The code below works in one sheet, but returns error in another: "Missing ; before statement". Occurs on the line let e = events[i];
So basically, code is ok as it works in one sheet. But in another sheet it works only if using var e = events[i];
It works anyway, but of course, would be nice to know why? Most probably some sheet setting or something I'm missing here?
function getHolidays() {
var startTime = new Date(2020,1-1,1);
var endTime = new Date(2020,12-1,31);
var calendarChoice = 'sl.slovenian#[email protected]';
var calendar = CalendarApp.getCalendarById(calendarChoice);
var events = calendar.getEvents(startTime, endTime);
var data = [];
for (var i = 0; i < events.length; i++)
{
let e = events[i];
data.push([e.getStartTime(), e.getTitle(), e.getDescription(), e.getAllTagKeys().join(',')]);
}
var s = SpreadsheetApp.getActive().getSheetByName('Google Calendar + Script');
s.getRange(2, 7, data.length, 4).setValues(data)
}
Upvotes: 0
Views: 707
Reputation: 38254
It's very likely that the script project given the error is set to use the old runtime (Rhino) instead of the new runtime (Chrome V8) as th old runtime doesn't support let
.
Possible solution: Enable the new runtime.
Related
Upvotes: 2