Google Calendar event id, not icalUID - google-apps-script

I'm building a script to retrieve certain events from my calendar and send an email for each qualifying event with a hyperlink to the event. For that I need event id, not icalUID. How do I get that? Here is my code (actual IDs and names were removed):
function GetFamilyEvents () {
//Gets all events that start/end/or span within next 30 days
var FamilyCalendar = CalendarApp.getCalendarById("someID#group.calendar.google.com");
var CurrentDate = new Date(); //Gets current date
var RangeEnd = new Date(CurrentDate.getTime() + 720 * 60 * 60 * 1000); //Adds 30 days in milliseconds to the current date
var FamilyEvents = FamilyCalendar.getEvents(CurrentDate,RangeEnd); //returns events that start, end, or encompass wihtin 30 days starting from today; Time range is Current Date to Range End
for(var i = 0; i<FamilyEvents.length; i++){
var EventTitle = FamilyEvents[i].getTitle();
var EventCreatedDate = FamilyEvents[i].getDateCreated();
var EventStartDate = FamilyEvents[i].getStartTime();
var EventEndDate = FamilyEvents[i].getEndTime();
var EventCreator = FamilyEvents[i].getCreators(); //Gets the creator of the event to email notificaiton to
var EventID = FamilyEvents[i].getID();
var CalendarID = FamilyCalendar.getId();
//Check if an event was created today AND does not have our names or "FYI" in its title
if(EventCreatedDate.valueOf() <= CurrentDate.valueOf() && EventTitle.indexOf('Name1')<0 && EventTitle.indexOf('Name2')<0 && EventTitle.indexOf('Name3')<0 && EventTitle.indexOf('Name4')<0 && EventTitle.indexOf('Name5')<0 && EventTitle.indexOf('FYI')<0)
{
//Creates variables for the HTML body of the email notification. The same variables are referenced in the body of the HTML template.
var EmailMessage = HtmlService.createTemplateFromFile("EmailMessage"); //"EmailMessage" is the name of the HTML file in this script.
EmailMessage.recepient = EventCreator;
EmailMessage.eventTitle = EventTitle;
EmailMessage.eventStartDate = EventStartDate;
EmailMessage.eventEndDate = EventEndDate;
EmailMessage.calendarID = CalendarID;
EmailMessage.eventID = EventID;
};
Thank you

From For that I need event id, not icalUID., when you want to retrieve the event ID, how about the following modification?
From:
var EventID = FamilyEvents[i].getID();
To:
var EventID = FamilyEvents[i].getId().split("#")[0];
Id of getId() is required to be modifieid.
getId() returns the value like ####google.com which is iCalUID. The event ID is retrieved from this as ###.
Reference:
getId()
Added:
From your replying,
what I meant was that my original code and your modifications give the same result: 2C18CFDB-E6B6-4653-AB65-21C990969103 - this is what I get for both options.
In this case, how about using Calendar API? By this, both the event ID and also the hyperlink of the event can be retrieved. When this is reflected in your script, it becomes as follows.
Sample script:
Before you use this, please enable Calendar API at Advanced Google services. And, please set your calendar ID.
function sample() {
var calendarId = "someID#group.calendar.google.com"; // Please set your calendar ID
//Gets all events that start/end/or span within next 30 days
var CurrentDate = new Date(); //Gets current date
var RangeEnd = new Date(CurrentDate.getTime() + 720 * 60 * 60 * 1000); //Adds 30 days in milliseconds to the current date
var items = Calendar.Events.list(calendarId, { timeMin: CurrentDate.toISOString(), timeMax: RangeEnd.toISOString(), maxResults: 2500 }).items;
items.forEach(e => {
var EventTitle = e.summary; // FamilyEvents[i].getTitle();
var EventCreatedDate = new Date(e.created); // FamilyEvents[i].getDateCreated();
var EventStartDate = new Date(e.start.dateTime || e.start.date);// FamilyEvents[i].getStartTime();
var EventEndDate = new Date(e.end.dateTime || e.end.date); // FamilyEvents[i].getEndTime();
var EventCreator = e.creator.email; // FamilyEvents[i].getCreators(); //Gets the creator of the event to email notificaiton to
var EventID = e.id; // FamilyEvents[i].getID();
var CalendarID = calendarId; // FamilyCalendar.getId();
var eventUrl = e.htmlLink; // If you want to retrieve the hyperlink of the event, you can use this.
//Check if an event was created today AND does not have our names or "FYI" in its title
if (EventCreatedDate.valueOf() <= CurrentDate.valueOf() && EventTitle.indexOf('Name1') < 0 && EventTitle.indexOf('Name2') < 0 && EventTitle.indexOf('Name3') < 0 && EventTitle.indexOf('Name4') < 0 && EventTitle.indexOf('Name5') < 0 && EventTitle.indexOf('FYI') < 0) {
//Creates variables for the HTML body of the email notification. The same variables are referenced in the body of the HTML template.
var EmailMessage = HtmlService.createTemplateFromFile("EmailMessage"); //"EmailMessage" is the name of the HTML file in this script.
EmailMessage.recepient = EventCreator;
EmailMessage.eventTitle = EventTitle;
EmailMessage.eventStartDate = EventStartDate;
EmailMessage.eventEndDate = EventEndDate;
EmailMessage.calendarID = CalendarID;
EmailMessage.eventID = EventID;
// do something
};
});
}
In this sample script, eventUrl is the hyperlink of the event.

The Google Event ID can be determined if you have both the iCalUID and the corresponding CalendarID that event belongs to. And once you have the Event ID, assembling a URL for the event is a piece of cake.
Step 1
Grab the first part of the iCalUID.. up to but not including the # sign.
Step 2
Concatenate the string from step 1 with a the CalendarID separated by a single space.
Step 3
Use the built-in Utilities class to encode the string from step 2 to a web-safe base64 string.
Step 4
Assemble your url
let str = EventID.split('#')[0].toString();
let str2 = str + ' ' + CalendarID;
let eid = Utilities.base64EncodeWebSafe(str2, Utilities.Charset.UTF_8);
let url = 'https://www.google.com/calendar/event?eid=' + eid;
We can simplify all that into a one liner. Add it to your for loop after the CalendarID variable declaration.
let url = 'https://www.google.com/calendar/event?eid=' + Utilities.base64EncodeWebSafe(EventID.split('#')[0].toString() + ' ' + CalendarID, Utilities.Charset.UTF_8);

Related

API call to calendar.events.import failed with error: Invalid iCalUID value [duplicate]

I'm building a script to retrieve certain events from my calendar and send an email for each qualifying event with a hyperlink to the event. For that I need event id, not icalUID. How do I get that? Here is my code (actual IDs and names were removed):
function GetFamilyEvents () {
//Gets all events that start/end/or span within next 30 days
var FamilyCalendar = CalendarApp.getCalendarById("someID#group.calendar.google.com");
var CurrentDate = new Date(); //Gets current date
var RangeEnd = new Date(CurrentDate.getTime() + 720 * 60 * 60 * 1000); //Adds 30 days in milliseconds to the current date
var FamilyEvents = FamilyCalendar.getEvents(CurrentDate,RangeEnd); //returns events that start, end, or encompass wihtin 30 days starting from today; Time range is Current Date to Range End
for(var i = 0; i<FamilyEvents.length; i++){
var EventTitle = FamilyEvents[i].getTitle();
var EventCreatedDate = FamilyEvents[i].getDateCreated();
var EventStartDate = FamilyEvents[i].getStartTime();
var EventEndDate = FamilyEvents[i].getEndTime();
var EventCreator = FamilyEvents[i].getCreators(); //Gets the creator of the event to email notificaiton to
var EventID = FamilyEvents[i].getID();
var CalendarID = FamilyCalendar.getId();
//Check if an event was created today AND does not have our names or "FYI" in its title
if(EventCreatedDate.valueOf() <= CurrentDate.valueOf() && EventTitle.indexOf('Name1')<0 && EventTitle.indexOf('Name2')<0 && EventTitle.indexOf('Name3')<0 && EventTitle.indexOf('Name4')<0 && EventTitle.indexOf('Name5')<0 && EventTitle.indexOf('FYI')<0)
{
//Creates variables for the HTML body of the email notification. The same variables are referenced in the body of the HTML template.
var EmailMessage = HtmlService.createTemplateFromFile("EmailMessage"); //"EmailMessage" is the name of the HTML file in this script.
EmailMessage.recepient = EventCreator;
EmailMessage.eventTitle = EventTitle;
EmailMessage.eventStartDate = EventStartDate;
EmailMessage.eventEndDate = EventEndDate;
EmailMessage.calendarID = CalendarID;
EmailMessage.eventID = EventID;
};
Thank you
From For that I need event id, not icalUID., when you want to retrieve the event ID, how about the following modification?
From:
var EventID = FamilyEvents[i].getID();
To:
var EventID = FamilyEvents[i].getId().split("#")[0];
Id of getId() is required to be modifieid.
getId() returns the value like ####google.com which is iCalUID. The event ID is retrieved from this as ###.
Reference:
getId()
Added:
From your replying,
what I meant was that my original code and your modifications give the same result: 2C18CFDB-E6B6-4653-AB65-21C990969103 - this is what I get for both options.
In this case, how about using Calendar API? By this, both the event ID and also the hyperlink of the event can be retrieved. When this is reflected in your script, it becomes as follows.
Sample script:
Before you use this, please enable Calendar API at Advanced Google services. And, please set your calendar ID.
function sample() {
var calendarId = "someID#group.calendar.google.com"; // Please set your calendar ID
//Gets all events that start/end/or span within next 30 days
var CurrentDate = new Date(); //Gets current date
var RangeEnd = new Date(CurrentDate.getTime() + 720 * 60 * 60 * 1000); //Adds 30 days in milliseconds to the current date
var items = Calendar.Events.list(calendarId, { timeMin: CurrentDate.toISOString(), timeMax: RangeEnd.toISOString(), maxResults: 2500 }).items;
items.forEach(e => {
var EventTitle = e.summary; // FamilyEvents[i].getTitle();
var EventCreatedDate = new Date(e.created); // FamilyEvents[i].getDateCreated();
var EventStartDate = new Date(e.start.dateTime || e.start.date);// FamilyEvents[i].getStartTime();
var EventEndDate = new Date(e.end.dateTime || e.end.date); // FamilyEvents[i].getEndTime();
var EventCreator = e.creator.email; // FamilyEvents[i].getCreators(); //Gets the creator of the event to email notificaiton to
var EventID = e.id; // FamilyEvents[i].getID();
var CalendarID = calendarId; // FamilyCalendar.getId();
var eventUrl = e.htmlLink; // If you want to retrieve the hyperlink of the event, you can use this.
//Check if an event was created today AND does not have our names or "FYI" in its title
if (EventCreatedDate.valueOf() <= CurrentDate.valueOf() && EventTitle.indexOf('Name1') < 0 && EventTitle.indexOf('Name2') < 0 && EventTitle.indexOf('Name3') < 0 && EventTitle.indexOf('Name4') < 0 && EventTitle.indexOf('Name5') < 0 && EventTitle.indexOf('FYI') < 0) {
//Creates variables for the HTML body of the email notification. The same variables are referenced in the body of the HTML template.
var EmailMessage = HtmlService.createTemplateFromFile("EmailMessage"); //"EmailMessage" is the name of the HTML file in this script.
EmailMessage.recepient = EventCreator;
EmailMessage.eventTitle = EventTitle;
EmailMessage.eventStartDate = EventStartDate;
EmailMessage.eventEndDate = EventEndDate;
EmailMessage.calendarID = CalendarID;
EmailMessage.eventID = EventID;
// do something
};
});
}
In this sample script, eventUrl is the hyperlink of the event.
The Google Event ID can be determined if you have both the iCalUID and the corresponding CalendarID that event belongs to. And once you have the Event ID, assembling a URL for the event is a piece of cake.
Step 1
Grab the first part of the iCalUID.. up to but not including the # sign.
Step 2
Concatenate the string from step 1 with a the CalendarID separated by a single space.
Step 3
Use the built-in Utilities class to encode the string from step 2 to a web-safe base64 string.
Step 4
Assemble your url
let str = EventID.split('#')[0].toString();
let str2 = str + ' ' + CalendarID;
let eid = Utilities.base64EncodeWebSafe(str2, Utilities.Charset.UTF_8);
let url = 'https://www.google.com/calendar/event?eid=' + eid;
We can simplify all that into a one liner. Add it to your for loop after the CalendarID variable declaration.
let url = 'https://www.google.com/calendar/event?eid=' + Utilities.base64EncodeWebSafe(EventID.split('#')[0].toString() + ' ' + CalendarID, Utilities.Charset.UTF_8);

How do i get event.getEventById('id') or event.getEventSeriesById('id') to return anything other than null

Is there a way to make the .getEventById or .getEventSereiesById return anyhting other than null? I get valid ID for the initial event creation and can make that into a full functional URL but cannot use it in its native environment for its native purpose.
I am trying to make a basic google sheets schedule system that can refer to the calendar invite to check for changes and update the sheet or vise versa based on which side is further out in time. The system will be used in an environment where the scheduling has multiple users and meetings can be moved around a lot, generally further out in time. Everything works right up until i try to get information from the calendar even, .getStartTime(), due to the .getEvent calls returning null. not sure how to fix what other sources are telling me is a nonfunctional command that yet still "functions as intended".
function IEPscheduler() {
var spreadsheet = SpreadsheetApp.getActiveSheet(); // call sheet
//var calendarID = spreadsheet.getRange("H1").getValue();
var eventCal = CalendarApp.getCalendarById("mascharterschool.com_0edapns33khde9ig0di31i2mvc#group.calendar.google.com");
var signups = spreadsheet.getRange("A2:C2").getValues();
var lr = spreadsheet.getLastRow();
var lc = spreadsheet.getLastColumn(); //
var count = spreadsheet.getRange(2,1,lr-1,lc-1).getValues();// get meeting data
for (x=0; x<count.length; x++){
var shift = count[x]; // pull row from meeting data
var Start = shift[0];
var End = shift[1];
var Student = shift[2];
var guests = shift[3];
var description = shift[4];
var location = shift[5];
var run=shift[6]; // run following based on status column
// new meeting is scheduled
if(run == null || run == ''){
var event = {
'location': location,
'description':description ,
'guests':guests +',',
'sendInvites': 'True',
}
var invite = eventCal.createEvent(Student, Start, End, event);
invite.setGuestsCanInviteOthers(true); // allow guests to invite others
var eventId = invite.getId();
var date = invite.getDateCreated();
spreadsheet.getRange(x+2,7).setValue('Invite created'); // set status in sheet
spreadsheet.getRange(x+2,8).setValue(date); // inital date for created meeting invite
spreadsheet.getRange(x+2,9).setValue(eventId);
}
// check existing meetings for updates
else {
var id = shift[9];
var invite = eventCal.getEventSeriesById('id');
// if the time or location has changed update calander
if(invite.getStartTime() !== Start || invite.getEndTime() !== End || invite.getLocation() !== location){
// if sheet override flagged
if(shift[lc-1] !== null || Shift[lc-1] !== ''){
invite.setTime(Start,End); // update start/end time
invite.setLocation(location); // update location
}
// if canalder invite is further out than spreadsheet --> update spreadsheet
if(invite.getStartTime() >> Start){
spreadsheet.getRange(x+2,1).setValue();
spreadsheet.getRange(x+2,2).setValue();
}
// if spread sheet time is later than invite --> updater invite
else{
invite.setTime(Start,End); // update start/end time
invite.setLocation(location); // update location
}
var date = invite.getLastUpdate();
spreadsheet.getRange(x+2,7).setValue('Updated'); // set new status in sheet
spreadsheet.getRange(x+2,8).setValue(date); // set date meeting was updated
}
// if guest list has changed ???
if
}
}
}
// set script to be runnable from sheet tool bar
function onOpen() {
var ui = SpreadsheetApp.getUi();
ui.createMenu('Sync to Calendar') // tool bar banner
.addItem('Create Events Now', 'IEPscheduler') // sub catageory (title, function to run)
.addToUi();
}
We actually figured it out shortly after posting and I couldn't get back to this. Turns out the ID from .getId is the iCalUID and the .getEventById() takes a iCalID. The difference is that the UID has '#google.com' appended to the end of the ID. Split at the '#' and the get event works perfectly.
It's a stupid quirk that the getId command returns the right data in a useless form that requires editing to be used for its intended purpose.
No nulls returned for me with this script:
function getEvents() {
const cal=CalendarApp.getDefaultCalendar();
const dt=new Date();
const start=new Date(dt.getFullYear(),dt.getMonth()-1,dt.getDate());
const end=new Date(dt.getFullYear(),dt.getMonth(),dt.getDate());
var events=cal.getEvents(start, end);
let eObj={idA:[],tA:[]}
events.forEach(function(ev,i){
eObj.idA.push(ev.getId());
eObj.tA.push(cal.getEventById(ev.getId()).getTitle());
});
Logger.log(JSON.stringify(eObj));
return eObj;
}

Multiple calendar ID's in a google script

New to programming and I have been hitting my head against the wall when trying to add multiple calendar ID's to the script below.
I need it to iterate through the rows and if the event hasn't been added to the calendar yet, add it to mine and to others' calendars, as the sheet gets updated.
function addToCal() {
var ss = SpreadsheetApp.getActiveSpreadsheet(),
sheet = ss.getSheetByName("ProductionSchedule"),
range = sheet.getActiveRange(),
row = range.getRow(),
data = sheet.getRange(row, 1, 1, 26).getValues(),
date = data[0][6];
if (date =='') return;
var today = new Date(),
startDate = new Date(today.setMonth(today.getMonth()-1)),
endDate = new Date(today.setMonth(today.getMonth()+6)),
calId = 'calendarID',
cal = CalendarApp.getCalendarById(calId),
events = cal.getEvents(startDate, endDate),
titles = [];
for (var i = 0, len = events.length; i < len; i++)
titles.push(events[i].getTitle());
var item = ('Produção de' + ' ' + data[0][3]),
qtd = ('Qtd (und): ' + data[0][5]),
local = ('Local de Produção: ' + data[0][4]);
var index = titles.indexOf(item),
ok = 1;
if (index > -1)
{
var eventDate = events[index].getAllDayStartDate();
if (eventDate.getTime() == date.getTime()) var ok = 0;
else events[index].deleteEvent();
}
if (ok)
cal.createAllDayEvent(item, date, {description: qtd, location: local})
.removeAllReminders();
}
Currently, it sets the events to my calendar containing Item Description as the event title, Product name, qty and Production Location in the description field. I would need the same information to be added to others' calendars.
Besides, this can't mark me as Busy and the event doesn't need to be an All Day event.
Any help is appreciated.
Cheers,
In order to repeat the calendar interactions for multiple calendars, you need to create an array of calendar IDs and loop through them.
One approach would be:
var CALENDER_IDS = [
"calendarID1",
"calendarID2",
"calendarID3",
]
func addToCal() {
... spreadsheet data extraction and date calculations ...
for (var i = 0, clen = CALENDER_IDS.length; i < clen; i++) {
var cal = CalendarApp.getCalendarById(CALENDER_IDS[i]);
... calendar interactions ...
}
}
If you use the above code, make sure to update the counter variable in the title loop (i.e. they both can't be i). Common practice is to make inner loops use j, k, etc.

Google Apps Script: Submit data into specified column

I am trying to find a script, or begin writing one, that takes a simple Google Form with a drop-down list of names (i.e. Tom, Jane) and a text area, and inputs both the date and the text into columns based on the selected name (i.e. Tom Date, Tom Comment). This is so I can make a quick entry feedback form for leaving individualized, date-based feedback for students, which they can then access later.
I looked through the GAS documentation and looked for examples, but as I am a novice, I really didn't know where to begin.
Any ideas on how to do this?
I think I did something similar but mine is for admins to observe teachers. I'm just learning as well, so I'm sure there are better ways to do this but it works. I definitely should have broken it up into more functions.
My form has a trigger to fire the onClose() when submitted. onClose() produces a Google Doc by reading the spreadsheet containing the form data in a nice format that the observer can then edit and share with the teacher. I wanted the Google Doc produced to have the name of the teacher being observed in the file name and I wanted it shared with the admin who did the observing.
The fact that some of the fields are dropdowns doesn't matter, it is just an itemResponse from the list of all responses.
function onClose()
{
var form = FormApp.openById(' whatever your form id is');
//the spreadsheet of the form responses
var formResponses = form.getResponses();
var d = new Date();
var currentTime = d.toLocaleTimeString();
var date = d.toLocaleDateString();
//Need to get the name of the teacher being observed
var formResponse = formResponses[formResponses.length-1];
var itemResponses = formResponse.getItemResponses();
var itemResponse = itemResponses[0]; //the teacher name dropdown box
var teacherName = itemResponse.getResponse() + '-' + itemResponses[1].getResponse();
//create the new document
var fileName = 'Observation-'+ teacherName + '-' + date + '-' + currentTime;
var doc = DocumentApp.create(fileName);
var activeDoc = DocumentApp.getActiveDocument();
var files = DriveApp.getFilesByName(fileName);
while (files.hasNext()) {
var file = files.next();
if (file.getName().equals(fileName))
{
//this is the last item on my form the name of the observer
var itemResponse21 = itemResponses[21];
var observer = itemResponse21.getResponse();
// Logger.log('Person to share with is ' + observer);
// share this google doc with the observer
file.addEditor(observer);
}
}
//ommittd a bunch of styles
//This would get all forms submitted, but I only need the last one
// so I just set the loop to get the last form submitted.
//leaving for loop just so I remember I can go through all forms again
//if I want to.
for (var i = formResponses.length-1; i < formResponses.length; i++) {
var formResponse = formResponses[i];
var itemResponses = formResponse.getItemResponses();
//get the individual responses within the form.addCheckboxItem()
for (var j = 0; j < itemResponses.length; j++) {
//pull the first item out again (even though I did for file name)
var itemResponse = itemResponses[j]; //teacher name from a dropbox
var itemResponse2 = itemResponses[j+1]; //date
var itemResponse3 = itemResponses[j+2]; //time
if (j == 0) //the first field on the form
{
//put the headings in
par3 = doc.appendParagraph(' SCHOOL NAME');
par3 = doc.appendParagraph('WALK IN OBSERVATION');
par3 = doc.appendParagraph('2013-2014');
//THIS is the teacher being observed and the date and time --- all on same line
var headingLine = itemResponse.getItem().getTitle() + '\t\t' + itemResponse2.getItem().getTitle() + ' / ' + itemResponse3.getItem().getTitle();
par1 = doc.appendParagraph(headingLine);
var answerLine = itemResponse.getResponse() + '\t\t\t\t\t' + itemResponse2.getResponse() + ' / ' + itemResponse3.getResponse();
par2 = doc.appendParagraph(answerLine);
j++; //do this to skip over date and time
j++;
} //end of j = 0;
else
// then I have a bunch of if statements for some of the
// specific fields I need to do something special with.
// After the last if, I just have an else to handle all other
// form responses that I don't do anything special for other than display.
//my last else is:
else
//THIS ELSE IS HANDLING ALL NON CHECK BOXES AND JUST DISPLAYING THE TITLE IN BOLD FONT, THE COMMENTS IN REGULAR FONT
{
par1 = doc.appendParagraph(itemResponse.getItem().getTitle());
par1.setAttributes(style);
par2 = doc.appendParagraph( itemResponse.getResponse());
par2.setAttributes(style);
} //END OF ELSE
} //end of for going through each cell in a row of the repsonses
} //end of for going through each row -- only had it set to do the very last row

Error occured: TypeError: Cannot call method "createEvent" of undefined via Google Script

Within the second half of my script and function, I keep getting this Cannot call method error, and I do not know why. I mimic'd the template script exactly, but I am unsure why it does not call the method.
Any insight would be greatly appreciated.
Thanks.
function createEvents(e){
//Get the active application
var app = UiApp.getActiveApplication();
try{
//get the entries;
var eventDate = e.parameter.eventDate;
var eventPeople = e.parameter.eventPeople;
var eventCompany = e.parameter.eventCompany;
var eventName = e.parameter.eventName;
var eventTime = e.parameter.eventTime;
var eventPhone = e.parameter.eventPhone;
var eventEmail = e.parameter.eventEmail;
var eventTaken = e.parameter.eventTaken;
//Get the calendar
var cal = CalendarApp.getCalendarsByName('Phoenix Reservations')[0];//Change the calendar name
var eventStartTime = eventDate;
//End time is calculated by adding an hour in the event start time
var eventEndTime = new Date(eventDate.valueOf()+60*60*1000);
//Create the events
cal.createEvent(eventPeople,eventCompany,eventName,eventTime,eventPhone,eventEmail,eventTaken);
//Log the entries in a spreadsheet
var ss = SpreadsheetApp.openById('KEY_TAKEN_OUT');//Change the spreadhseet key to yours
var sheet = ss.getSheets()[0];
sheet.getRange(sheet.getLastRow()+1, 1, 1, 5).setValues([[new Date(), eventDate,eventPeople,eventCompany,eventName,eventTime,eventPhone,eventEmail,eventTaken, 'Event created']]);
//Show the confirmation message
app.add(app.createLabel('Event created Successfully'));
//make the form panel invisible
app.getElementById('panel').setVisible(false);
return app;
}
//If an error occurs, show it on the panel
catch(e){
app.add(app.createLabel('Error occured: '+e));
return app;
}
}
This line probably returns nothing :
var cal = CalendarApp.getCalendarsByName('Phoenix Reservations')[0];//Change the calendar name
You could log it to confirm like this Logger.log(cal)
Is 'Phoenix Reservations' a calendar name that you own or that you have write access to ?
EDIT : could you test this simple function to see if everything is ok with this calendar?
It will create an event just now.
function testcal(){
var cal = CalendarApp.openByName('Phoenix Reservations');// or you can replace this with your var definition : same result normally ;-)
if (cal) {
var title = 'Test Event';
var start = new Date();
var end = new Date(start.valueOf()+60*60*1000);
Logger.log(cal.getName()+' '+start+' '+end)
var desc = 'Created using Google Script';
var loc = 'there';
var event = cal.createEvent(title, start, end, {
description : desc,
location : loc
});
}
}
EDIT 2 : I modified the logger to make it show the calendar name.