I need help in Creating a google apps script to create events in Google Calendar, following the code I'm using but gives the error "Cannot read property 'setColor' of null" for color settings.
function myFunction() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheetByName("Test jun")
var index = 2;
var lastRow = sheet.getLastRow();
for (; index <= lastRow; index++) {
var title = sheet.getRange(index, 1, 1, 1).getValue();
var startTime = sheet.getRange(index, 2, 1, 1).getValue();
var endTime = sheet.getRange(index, 3, 1, 1).getValue();
var description = sheet.getRange(index, 4, 1, 1).getValue();
var location = sheet.getRange(index, 5, 1, 1).getValue();
var guests = sheet.getRange(index, 6, 1, 1).getValue();
var eventColour = sheet.getRange(index, 7, 1, 1).getValue();
var sendInvites = true;
var calendar = CalendarApp.getCalendarById("[email protected]").createEvent(title, startTime, endTime,
{ description: description, location: location, guests: guests, sendInvites: sendInvites }).getId();
if (eventColour === 'Condition1') CalendarApp.getEventById(calendar).setColor("10")
if (eventColour === "Condition2") CalendarApp.getEventById(calendar).setColor("11");
if (eventColour === "Condition3") CalendarApp.getEventById(calendar).setColor("12");
if (eventColour === "Condition4") CalendarApp.getEventById(calendar).setColor("13");
}// End of For Loop
}// End of Function
please help.