I want to have google sheets create a recurring event on google calendar.
Is there a way to make this section of code dependent on variables from a spreadsheet? I would like to be able to select the days of the week on my spreadsheet instead of having to type them in.
.onlyOnWeekday([CalendarApp.Weekday.MONDAY,CalendarApp.Weekday.WEDNESDAY])
Here is my function
function newStudentCalendar() {
var app = SpreadsheetApp;
var sheet = app.getActiveSpreadsheet().getActiveSheet();
var studentName = sheet.getRange(2, 1).getValue();
// set time variables for lesson creation
var year = sheet.getRange(2, 5).getValue();
var month = sheet.getRange(2, 3).getValue();
var day1 = sheet.getRange(2, 4).getValue();
var startTime = sheet.getRange(2, 6).getValue();
var endTime = sheet.getRange(2, 7).getValue();
//Creates the new students calendar
var calendar = CalendarApp.createCalendar(studentName);
Logger.log('Created the calendar "%s", with the ID "%s".',
calendar.getName(), calendar.getId());
var calendarID = calendar.getId()
//Creates the recuring lessons
var lessons = CalendarApp.getCalendarById(calendarID).createEventSeries(studentName + " lesson",
new Date(month + day1 + ',' + year + ' ' + startTime),
new Date(month + day1 + ',' + year + ' ' + endTime),
CalendarApp.newRecurrence().addWeeklyRule()
.onlyOnWeekdays([CalendarApp.Weekday.MONDAY, CalendarApp.Weekday.WEDNESDAY]));
Logger.log('Event Series ID: ' + lessons.getId());
}