Reputation: 41
function onOpen() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var calendarName = "CALENDAR";
var calTimeZone = CalendarApp.openByName(calendarName).getTimeZone();
var menuEntries = [ {name: "Update Calendar", functionName: "cal1"} ];
ss.addMenu("Calendar", menuEntries);
ss.setSpreadsheetTimeZone(calTimeZone);
}
function cal1() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var dataSheet = ss.getSheetByName("Sheet1");
var calendarName = "CALENDAR";
var calTimeZone = CalendarApp.openByName(calendarName).getTimeZone();
var startRow = 3;
var numRows = 100;
var dataRange = dataSheet.getRange(startRow, 1, numRows, 26);
var data = dataRange.getValues();
var cal = CalendarApp.getCalendarsByName("CALENDAR")[0];
for (i in data) {
var row = data[i];
if (row[3] == "Add") {
var title = row[24]; // Column with Title
var desc = row[21]; // Column with Description
var startdate = row[12]; //Column with Date
var enddate = row[14]; //Column with Location
cal.createEvent(title, startdate, enddate);
}
}
}
This is a simple script that's supposed to look through my spreadsheet and add it to my calendar if column 3 is "Add". The code runs without any error but when I check my calendar there is nothing there. Am I doing something wrong here?
Upvotes: 0
Views: 58
Reputation: 41
After checking the logger I realised that the indexing starts from 0 (column C = row[2], not row[3]). It's a silly mistake, and as much as I'd like to delete this question away I thought it would be good to put this out there in case someone does the same thing.
Upvotes: 1