How to create an event on every organisation member calendar? - google-apps-script

I need to create an event in everyone's calendar of my organization. This event is a reminder of an action everyone needs to take before a certain date, but this date is not the same every month, so I can't do a recurring event. I don't want to add everyone as attendee because I want everyone keep the event on the calendar and not just answer "don't participate" and forgot to do what they need to do at the good time.
To do this, I already wrote a code that gets every active account from the organisation, gets the start date, end date, event title and event description from a google sheet. It works for my calendar and calendars of people I add manually on my list "other calendars" in google calendar. But the script doesn't create the event in agendas of people in my organisation not present on my "other calendar" list.
function getAllPeopleFromDirectory() {
var pageToken;
var page;
var usersId = [];
do {
page = AdminDirectory.Users.list({
domain:'mydomain.com',
orderBy: 'givenName',
maxResults: 400,
query: "orgUnitPath=/ isSuspended=False",
pageToken: pageToken
});
var users = page.users;
if(users) {
for (var i=0; i< users.length; i++) {
var user = users[i];
usersId.push(user.primaryEmail);
}
} else {
Logger.log('No users found.');
}
pageToken = page.nextPageToken;
} while(pageToken);
if (usersId.length != 0){
setUpReminder(usersId);
}
}
function setUpReminder(calendarIDs) {
var ss = SpreadsheetApp.openById("SPREADSHEET_ID");
var sheet = ss.getSheetByName('reminder');
var range = sheet.getDataRange();
var values = range.getValues();
for (var i = 0; i < calendarIDs.length; i++) {
setUpCalendar(values, range, calendarIDs[i]);
}
}
function setUpCalendar(values, range, calendarId) {
var cal = CalendarApp.getCalendarById(calendarId);
for (var i = 1; i < values.length; i++) {
var session = values[i];
var date = new Date(session[1]);
var now = new Date();
if (date.getMonth() == now.getMonth()) {
var title = session[4];
var start = joinDateAndTime(session[1], session[2]);
var end = joinDateAndTime(session[1], session[3]);
var options = {location: session[5], sendInvites: false, description: session[8]};
var event = cal.createEvent(title, start, end, options).setGuestsCanSeeGuests(true);
}
}
range.setValues(values);
}
function joinDateAndTime(date, time) {
date = new Date(date);
date.setHours(time.getHours());
date.setMinutes(time.getMinutes());
return date;
}
When I call "CalendarApp.getCalendarById" with everyone who isn't on my other calendars, the function returns null so cal.createEvent raises an error...
Does anyone have an idea how to make this correctly?
Maybe I can add and remove people to my other calendar every time I run the script, it's not the best solution but if someone knows how to do this, it would be cool!

Instead of fetching user-specific (primary) calendars and updating them with events one-by-one, a better approach is to create a custom calendar (aka. a secondary calendar) that's shared among all the users under your GSuite domain.
Here's an excerpt from the Calendar API reference documentation:
...you can explicitly create any number of other calendars; these calendars can be modified, deleted, and shared among multiple users.
So, all you need do is update the secondary calendar and its events will be reflected in your users' calendar view (but only if your users have the custom calendar enabled).
See Primary Calendars and other calendars
See Sharing Calendars.

Related

google calendar api v3 get id of last modified event

I want to script behavior when people insert event in my calendar.
(e.g. when they add something into my "focus time"). I was able to connect an appscript "trigger" to call onEventUpdate. Sadly AppScript does not give you the event id for the event that was modified... (can you confirm the API does not offer this?).
So I tried to fetch the "last updated" events instead:
function getOptions() {
var now = new Date();
var yesterday = new Date();
yesterday.setDate(now.getDate() - 1);
console.log(yesterday.toISOString())
return {
updateMin: yesterday.toISOString(),
maxResults: 2,
orderBy: 'updated',
singleEvents: true,
showDeleted: false
}
}
function onEventUpdate() {
var options = getOptions();
var calendarId = Session.getActiveUser().getEmail();
// var calendar = CalendarApp.getCalendarById(calendarId);
// console.log(calendar.getName());
var events = Calendar.Events.list(calendarId, options);
if(!events.items) return
for (var i = 0; i < events.items.length; i++) {
var event = events.items[i];
console.log(event.summary + " # " + event.start['dateTime']);
}
}
Yet, I have just modified an event, but instead I am getting events from the past (i.e. August, 2mo ago...):
5:11:21 PM Notice Execution started
5:11:21 PM Info 2022-10-29T00:11:21.826Z
5:11:22 PM Info Old Meeting # 2022-08-08T17:00:00-07:00
5:11:22 PM Info Old Meeting # 2022-08-03T14:00:00-07:00
5:11:22 PM Notice Execution completed
Thoughts?
I believe your goal is as follows.
You want to retrieve the last updated event in a Google Calendar using Google Apps Script.
In the current stage, orderBy of "Events: list" can be used with only "ascending". When I saw your script, I thought that the reason for your current issue might be due to this. If "descending" was used with orderBy, your script might be able to be used. But, in the current stage, it seems that this cannot be used.
So, in the current stage, in order to retrieve the last updated event, I thought that it is required to retrieve all events with your getOptions(), and the last element is required to be retrieved. When this is reflected in your script, how about the following modification?
Modified script:
function getOptions() {
var now = new Date();
var yesterday = new Date();
yesterday.setDate(now.getDate() - 1);
console.log(yesterday.toISOString())
return {
updatedMin: yesterday.toISOString(),
maxResults: 2500, // Modified
orderBy: 'updated',
singleEvents: true,
showDeleted: false
}
}
function onEventUpdate() {
var options = getOptions();
var calendarId = Session.getActiveUser().getEmail();
// I modified the below script.
var eventList = [];
var pageToken = null;
do {
options.pageToken = pageToken;
var events = Calendar.Events.list(calendarId, options);
if (events.items.length > 0) {
eventList = [...eventList, ...events.items];
}
pageToken = events.nextPageToken;
} while (pageToken);
var lastUpdatedEvent = eventList.pop(); // You can retrieve the last updated event.
var lastUpdatedEventId = lastUpdatedEvent.id; // You can retrieve the event ID of the last updated event.
}
Note:
About I was able to connect an appscript "trigger" to call onEventUpdate. Sadly AppScript does not give you the event id for the event that was modified, how about reporting this to the Google issue tracker as a future request?
Reference:
Events: list
Alright, I achieved what I wanted to (thanks for spotting my typo). I take some risk, as I assume there is no more than 50 edited events in the last hour (although risk could be reduced by making this delta smaller).
This is what the overly-convoluted way appscript needs (i.e. they could have just given me a calendar-event object as an argument to the trigger? oh well)
This is just a simple example, as now I can programmatically edit my calendar at will :)
function getOptions() {
var now = new Date();
TIME_DIFF = 60 * 60 * 1000;
var earlier = new Date(now.getTime() - TIME_DIFF)
return {
updatedMin: earlier.toISOString(),
maxResults: 50,
orderBy: 'updated',
singleEvents: true,
showDeleted: false
}
}
function getLastEditedEvent() {
// returns https://developers.google.com/apps-script/reference/calendar/calendar-event
var options = getOptions();
var calendarId = Session.getActiveUser().getEmail();
var events = Calendar.Events.list(calendarId, options);
if(!events.items) return undefined;
var _event = events.items[events.items.length-1];
return CalendarApp.getEventById(_event.id);
}
function onEventUpdate() {
// sadly event update contains no information
var event = getLastEditedEvent()
if(event == undefined) return;
console.log('Modifying: ' + event.getTitle() + ' # ' + event.getStartTime());
event.setColor(CalendarApp.EventColor.PALE_BLUE);
}

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;
}

Listing Google calendar events using API

I am trying to write a Google Apps script to modify calendar events so I have modified an example to list events first. When I try debugging this it reports an error that "Calendar is not defined" on the line "events = Calendar.Events.list(calendarId, options);"
I have enabled the advanced calendar API, and am basing my script on one from the Google documentation, so I assume that one worked. Is there anything else I need to do to access the relevant objects and methods?
/*
Adapted from code in https://developers.google.com/apps-script/advanced/calendar
*/
function syncColourCode() {
var calendarId = CalendarApp.getDefaultCalendar();
var properties = PropertiesService.getUserProperties();
var fullSync = properties.getProperty('fullSync'); // sync status is stored in user properties
var options = {
maxResults: 100
};
var syncToken = properties.getProperty('syncToken'); // pointer token from last sync also stored in user properties
if (syncToken && !fullSync) { // if there is a sync token from last time and sync status has not been set to full sync
options.syncToken = syncToken; // adds the current sync token to the list of sync options
} else {
// Sync events from today onwards.
options.timeMin = new Date().toISOString(); //change to new Date().toISOString() from getRelativeDate(-1, 0).toISOString()
}
// Retrieve events one page at a time.
var events;
var pageToken;
do {
try {
options.pageToken = pageToken;
events = Calendar.Events.list(calendarId, options);
} catch (e) {
Not a google-apps expert, but from reviewing the code, I see a possible problem. At no point do I see your code checking to see if getDefaultCalendar() actually returned a valid calendar ID. Later your code uses that ID under the assumption that it is good. Have you checked the value of calendarId that is returned?
Sometimes you have to read a little deeper into the message, but I always try to start with trusting the error return. In this case "Calendar is not defined" makes me question the value of calendarId.
It seem that Google made some change so that there is no Calendar reference from the AppScript API.
Anyway to get the event you may use this API:
CalendarApp.getEvents(startTime, endTime)
https://developers.google.com/apps-script/reference/calendar/calendar-app#geteventsstarttime-endtime
Below are my example function running within google sheet.
function listEventsWithinTwoMonth(){
var calendar = CalendarApp.getDefaultCalendar();
var spreadsheet = SpreadsheetApp.getActiveSheet();
var now = new Date();
var twoMonthFromNow = new Date(now.getTime() + (24 * 60 * 60 * 30 * 4 * 1000));
var events = calendar.getEvents(now, twoMonthFromNow);
if (events.length > 0) {
// Header Rows
spreadsheet.appendRow(["#่","id","StartTime","EndTime","Title","Description"]);
for (i = 0; i < events.length; i++) {
var event = events[i];
Logger.log("" + (i+1) + event.getId() +" "+ event.getStartTime()+" "+event.getEndTime()+" "+event.getTitle()+" "+event.getDescription())
spreadsheet.appendRow([(i+1),event.getId(),event.getStartTime(),event.getEndTime(),event.getTitle(),event.getDescription()]);
}
} else {
Logger.log('No upcoming events found.');
}
}
Hope this help.
CalendarApp.getDefaultCalendar() retrieves an object of the class Calendar that has multiple properties, among others an Id.
To retrieve the calendar Id, you need to define
var calendarId = CalendarApp.getDefaultCalendar().getId();

Google Apps Script: "Script function not found" error

I have been searching around for a solution for my issue but have not been able to find one, and as a result am writing my first question in Stack Overflow.
I am currently writing a simple program on Google Apps Script that sends out an email reminder to a user if they forget to submit a Google Form by a certain date. Right now I have 3 different functions: onFormSubmit, scheduleTrigger, and reminderEmail. Below is the code I have written out thus far:
/**
This function searches the Google Form for the date when the previous
session was held & the date when the next session will be held.
This function also calculates the date when to remind the user if they
forget to submit the Google Form. This reminder date is calculated to be 2
days after the date when the next session is held.
This function calls the next function: scheduleTrigger.
*/
function onFormSubmit(e) {
var form = FormApp.getActiveForm();
var frm = FormApp.getActiveForm().getItems();
var futureDate = new Date(e.response.getResponseForItem(frm[3]).getResponse());
var pastDate = new Date(e.response.getResponseForItem(frm[0]).getResponse());
var reminderDate = new Date(futureDate.setDate(futureDate.getDate() + 2));
futureDate.setDate(futureDate.getDate() - 2);
scheduleTrigger(reminderDate, futureDate, pastDate, form);
}
/**
This function schedules the reminder email trigger at a specific date. The
specific date is the reminder date that was calculated in the previous function.
This function calls the next function: reminderEmail.
*/
function scheduleTrigger(reminderDate, futureDate, pastDate, form) {
ScriptApp.newTrigger('reminderEmail(reminderDate, futureDate, pastDate, form)').timeBased().atDate(reminderDate.getFullYear(), reminderDate.getMonth(), reminderDate.getDate()).inTimezone('America/New_York').create();
}
/**
This function checks the submissions if the form has been submitted.
If there is no submission, then it sends out an email reminder.
*/
function reminderEmail(reminderDate, futureDate, pastDate, form) {
var count = 0;
var formResponses = form.getResponses();
for (var i = 0; i < formResponses.length; i++) {
var formResponse = formResponses[i];
var itemResponses = formResponse.getItemResponses();
for (var j = 0; j < itemResponses.length; j++) {
var itemResponse = itemResponses[j];
if (itemResponse == futureDate) {
count++;
}
}
}
if (count != 2) {
MailApp.sendEmail("test#gmail.com",
"Submit Form Reminder",
"Hey! You didn't fill out the form yet!");
};
}
The issue I am running into is that I receive an error message stating "The selected function cannot be found" for function reminderEmail whenever I run the program. I have looked around and followed previous posts made to solve this issue, such as renaming the function and restarting with a whole new different Google From but nothing has worked. I also have full ownership and authorization to the script so permissions shouldn't be an issue.
Please let me know if you have any ideas on how to solve this problem. Any and all feedback is welcome! If there is any part of my question that is unclear please let me know. Thank you for taking the time to read through this lengthy post.
The reason it's failing is because you need to only pass the function name to ScriptApp.newTrigger. You can't send parameters with it, that's something you'll have to handle in other ways.
Documentation
/**
This function searches the Google Form for the date when the previous session was held & the date when the next session will be held.
This function also calculates the date when to remind the user if they forget to submit the Google Form. This reminder date is calculated to be 2 days after the date when the next session is held.
This function calls the next function: scheduleTrigger.
*/
function onFormSubmit(e) {
var form = FormApp.getActiveForm();
var frm = FormApp.getActiveForm().getItems();
var futureDate = new
Date(e.response.getResponseForItem(frm[3]).getResponse());
var pastDate = new
Date(e.response.getResponseForItem(frm[0]).getResponse());
var reminderDate = new Date(futureDate.setDate(futureDate.getDate() + 2));
futureDate.setDate(futureDate.getDate() - 2);
scheduleTrigger(reminderDate);
}
/**
This function schedules the reminder email trigger at a specific date. The specific date is the reminder date that was calculated in the previous function.
This function calls the next function: reminderEmail.
*/
function scheduleTrigger(reminderDate) {
ScriptApp.newTrigger('reminderEmail').timeBased().atDate(reminderDate.getFullYear(), reminderDate.getMonth(), reminderDate.getDate()).inTimezone('America/New_York').create();
}
/**
This function checks the submissions if the form has been submitted. If there is no submission, then it sends out an email reminder.
*/
function reminderEmail() {
var form = FormApp.getActiveForm();
var count = 0;
var formResponses = form.getResponses();
for (var i = 0; i < formResponses.length; i++) {
var formResponse = formResponses[i];
var itemResponses = formResponse.getItemResponses();
for (var j = 0; j < itemResponses.length; j++) {
var itemResponse = itemResponses[j];
if (itemResponse == futureDate) { // Unsure what this part is for, perhaps you should find another way to calculate this.
count++;
}
}
}
if (count != 2) {
MailApp.sendEmail("test#gmail.com",
"Submit Form Reminder",
"Hey! You didn't fill out the form yet!");
};
}
I was able to clean up your code to a way it should work, but not sure about futureDate in the reminderEmail function.

Checking a Google Calendar Event's Existence

I have a very basic problem within my whole code which became a head-ache for a couple of days. I have made an extensive research on this issue however couldn't be able to find an exact solution (or I have missed the one's that I might have found). Here it is:
I have a spreadsheet, where I log in Google Calendar events with their properties including the id of the event. Sometimes, I clean up the Google Calendar manually and just want to run a code which checks the events existence in the calendar and if not delete the row. My code is:
function cleanCal(calid, eventid) {
var calid = 'my calendar id';
var eventid = 'event id';
var event = CalendarApp.getOwnedCalendarById(calid).getEventById(eventid);
if (event) {
event.deleteEvent();
// clean-up sheet
} else {
// clean-up sheet
}
}
Basically if the event is in the calendar, the code shall delete it first and then clean the sheet, if it's not there, it should clean the sheet only. However, when the code is executed, though the calendar event is not there, the if statement returns true and raises an error when trying to delete the event as it's actually not there. I haven't been able to find out the reason, how and why the event object return true though the event is not existing. Where am I doing wrong?? Thanks for replying and any help is really appreciated.
[EDIT]
This is the code that I use to check events existence with Calendar API v3
function verifyCalendarEvent_OLD(calid, eventid) {
var cal = CalendarApp.getCalendarById(calid)
var exists = true;
var response = Calendar.Events.list(
calid, {
showDeleted: true,
fields: "items(id,status,summary)"
}
);
for (var i = 0; i < response.items.length; i++) {
if (response.items[i].id == eventid.split("#")[0] && response.items[i].status == "cancelled") {
exists = false;
break;
}
}
return exists;
}
How about this answer?
Modification points :
For example, if there is no event of the event ID, CalendarApp.getOwnedCalendarById(calid).getEventById(eventid) returns null. When this is evaluated by if, that is used as false.
So I thought that you might try to retrieve the event which has already been removed. Because at Google Calendar, even if the event is removed, the event ID is remained. So although there is no event for the event ID, if (event) {} in your script returns true. I confirmed that CalendarApp.getOwnedCalendarById(calid).getEventById(eventid) retrieves the removed events. For this situation, you can know whether the event is removed by confirming the event status.
When the event status is confirmed, it indicates that the event is still not removed.
When the event status is cancelled, it indicates that the event has already been removed.
Preparation to use this modified sample script :
When you use this modified script, please enable Calendar API at Advanced Google Services and API console.
Enable Calendar API v3 at Advanced Google Services
On script editor
Resources -> Advanced Google Services
Turn on Calendar API v3
Enable Calendar API at API console
On script editor
Resources -> Cloud Platform project
View API console
At Getting started, click Enable APIs and get credentials like keys.
At left side, click Library.
At Search for APIs & services, input "Calendar". And click Calendar API.
Click Enable button.
If API has already been enabled, please don't turn off.
When you run this script, if an error occurs, you might be required to wait few minutes until the API is enabled.
Modified script :
function cleanCal(calid, eventid) {
var calid = 'my calendar id';
var eventid = 'event id';
var status = Calendar.Events.get(calid, eventid).status; // Added
if (status == "confirmed") { // Modified
var event = CalendarApp.getOwnedCalendarById(calid).getEventById(eventid); // Added
event.deleteEvent();
// clean-up sheet
} else {
// clean-up sheet
}
}
If I misunderstand your question, I'm sorry.
Edit :
In my environment, the events removed by manual and script can be retrieved as status=cancelled. Since I didn't know your situation, I prepared a sample script. This sample script is a simple flow.
Create new event.
Delete the created event.
Confirm the deleted event.
Here, your additional script was used.
Sample script :
function deleteeventa() {
// Create new event
var calid = 'my calendar id';
var c = CalendarApp.getCalendarById(calid);
var r = c.createEvent("sample event for deleting", new Date(2018,0,11,00,00), new Date(2018,0,11,01,00));
// Delete the created new event
var eventid = r.getId().split('#')[0];
var event = c.getEventById(eventid);
event.deleteEvent();
// Your additional script
var exists = true;
var response = Calendar.Events.list(
calid, {
showDeleted: true,
fields: "items(id,status,summary)"
}
);
for (var i = 0; i < response.items.length; i++) {
if (response.items[i].id == eventid && response.items[i].status == "cancelled") {
exists = false;
break;
}
}
Logger.log("%s, %s, %s", r.getTitle(), r.getId(), exists)
}
Result :
sample event for deleting, ######google.com, false
Following Tanaike's great help, I have come up with this code snippet which - as far as I have tested - works fine for now. Hope it might be helpful for other users. Here is the code fragment:
function verifyCalendarEvent(calid, eventid) {
var cal = CalendarApp.getCalendarById(calid)
eventid = eventid.split("#")[0];
var exists = true;
var eventIds = [];
var eventStats = [];
var response = Calendar.Events.list(
calid, {
showDeleted: true,
fields: "items(id,status,summary)"
}
);
for (var i = 0; i < response.items.length; i++) {
eventIds.push(response.items[i].id);
}
for (var i = 0; i < response.items.length; i++) {
eventStats.push(response.items[i].status);
}
if (eventIds.indexOf(eventid) > 0) {
for (var i = 0; i < eventIds.length; i++) {
if (eventIds[i] == eventid && eventStats[i] == "cancelled") {
exists = false;
}
}
} else {
exists = false;
}
Logger.log("Calendar Event ["+eventid+"] exists? >> "+exists);
return exists;
}