I am trying to write the Script to turn single rows of a Spreadsheet into a Google Calendar event and invite the emails in one of the columns to the event. This will be used in a school setting where students are signing up for workshops and I want to add it to their Google Calendar.
Here is the code I've been working with from another forum on here. It hasn't been able to send the invite/add to the other calendar.
function main() {
var ss = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet()
var values = ss.getDataRange().getDisplayValues()
var lc = ss.getLastColumn()
for (var i = 1; i < values.length; i++) {
var evId = processLine(values[i], lc) // create the event and get id of the event
ss.getRange(i, lc).setValue(evId) // write the id of the event in the last column of the sheet
}
}
function processLine(x, lc) {
var jobType = x[5]
var evId = x[lc-1]
// check job type
if (jobType == 1 && evId == '') {
// summary
// description
var freq = x[6]
var description = type + ' - ' + dur + ' - ' + freq
// location
var location = x[10]
// date
var start = x[8]
var end = x[9]
var date = x[7]
// formated date
var eStart = new Date(date + ' ' + start)
var eEnd = new Date(date + ' ' + end)
// options
var opts = {
location: location
}
// SINGLE EVENTS
if (freq == 'Once Off') {
var ev = CalendarApp.createEvent(summary, eStart, eEnd, opts)
} else {
// CREATE EVENT
var ev = CalendarApp.createEventSeries(summary, eStart, eEnd, recurrence, opts)
}
// ADD PARAMETERS
ev.setColor(CalendarApp.EventColor.YELLOW)
ev.setDescription(description)
console.log(ev.getId())
return ev.getId()
}
}