I'm building a two-way script to go back and forth between Google Sheets and Google Calendar, and I'm wondering how to tell whether a CalendarEvent has been deleted.
Currently, I store event IDs in the spreadsheet every time an event is created, then I use that event ID to read/write subsequent updates to that event:
var event = eventcal.getEventById(eventId);
But I don't see a way in the documentation to determine whether a CalendarEvent has been deleted in the calendar. Retrieving a recently deleted event using the method above simply returns the CalendarEvent since it lives in the Recycle Bin. event.getLastUpdated() is also too general for me since I'd like to do different things for updated/rescheduled events and deleted events.
Use Reports API instead
When listing the Activities for a specific App you can specify the eventName and filters parameters to look for deleted events given a certain Calendar.
References
Reports API > Aplication Name
Method: activities.list
Google Calendar > Delete Event
Related
I am able to create Google calendar events from a Google sheet. I want to know if I can view and edit Google calendar events in a Google sheet.
I have read the following, but I am unsure if it will do what I want...
"Allows a script to read and update the user's Google Calendar. This class provides direct access to the user's default calendar, as well as the ability to retrieve additional calendars that the user owns or is subscribed to.
Yes you can.
Query the calander to get the events (with the event id)
Write to the sheet
Have some logic in the sheet, like a dropdown with status (update/delete/untouched/create)
Do your thing in the sheet and then call the function
Based on the dropdown status call functions ti handle the logic that comes with the status.
Reset the dropdown in the sheet / delete the row?
That would be the high over logic.
I need to determine if the onChange event in Google sheets is triggered by a Google service account or by a person, because I want to process the changed data only if the trigger source was human-made direct editing, otherwise stop processing.
I tried to identify it with Session.getActiverUser(), but, although the change is through the service account, shows my own email address.
I can not find anything on the Internet, nor in the Google documentation.
PS: to be more clear, I did bidirectional syncing from Firebase Realtime Database to Sheets and vice versa. Therefore, to avoid redundant update cycle, I want to stop processing as soon as change/update happens on behalf of the Service Account.
Or maybe there is some other way to avoid loop problem. I will be glad of any help
So, basically it is a bit a hacky way, but it works.
As #TheMaster suggested onChange event parameter e contains user node, which in case of Service Account is empty, thus could be used to distinguish change event sources.
I own a calendar which is shared with a certain number of people (subscribers). I would like to keep track of which events the subscribers add/copy to their personal calendars. The calendar is created by a spreadsheet using Apps Scripts and I have full access on anything needed. The emails of the subscribers are known but I can't access info on their side.
I would be happy with a boolean of a kind showing if an event has been copied, but if that's possible then I believe I'll be able to also count which and how many subscribers copied which events.
No, the Calendar API doesn't have any way to obtain if and event was copied. In any case, the event copy option is just a template from the original event that can be completely modified before being created.
I have created a app in appmaker. In that there is a table which should get refreshed (i.e a particular appscript function (client-side function)should run to refresh the table) whenever any change in calendar events of a particular calendar on the current day takes place.
How to set such type of trigger?
I did some R&D and found that there is something called watch function in calendar API but I'm not sure if it is useful for my problem.
By table I am referring to appmaker table widget.
If setting the appscript calendar trigger, Client refresh may be a problem. Because in my ui above the table there is a dropdown to select the calendarId which refreshes the table by running the below code:
var calendarId=app.pages.Events.descendants.Dropdown1.value;
google.script.run.withSuccessHandler(function() {
app.datasources.Events.load();
}).getTodayEvents(calendarId);
/* In getTodayEvents() current day events of the calendarId are
fetched from that calendar and stored in DB */
Can this happen from server side through trigger?
Also trigger should be based on the calendarId currently selected in dropdown.
So the calendarId needs to be dynamic in the trigger.
A calendar watch requires an webhook that will process some logic when there is an event modification(create, update, delete). Unfortunately, App Maker does not yet support such a thing and here is a discussion about it Calling App Maker server scripts from outside of App Maker UI. On top of that, you would require to interact with the client side rather than the server, so definitely not.
In this case, the best thing you can do is set an interval that will refresh the ui every certain seconds or minutes.
setInterval(function(){
app.datasources.myDatasource.load();
},60000); //60 seconds
A more advanced way of approaching this would be using firebase and cloud functions. I have implemented firebase on some projects with reliable results. You can read more about firebase and cloud functions on the below links:
https://firebase.google.com/docs/web/setup
https://cloud.google.com/functions/docs/
This may or may not be applicable to your use case but for non-app-maker script projects I'd do the following:
Go to your GSuite Developer Hub via https://script.google.com/home/my
Select the desired script project
On the right is a box titled "Project Details", click the menu icon (top-right) and select "Triggers"
Click the "Add trigger" button (bottom-right)
In the pop-up modal select the function you wish to run, and set the event source to "Calendar".
Note that this "Calendar" trigger can only detect updates to your primary calendar. Changes to secondary calendars you create will not be tracked.
I have a Google App for Business.
Is it possible to access other user's calendar to input & retrieve event?
I only know how to do it for my own calendar, but not others.
I have super administrator access.
Yes, you can get any calendar by it's ID, and then just get the events. As per your comment I don't believe that it will allow you to get any calendar in the domain, you appear to need to be subscribed. Whether this is expected or not I'm unsure.
Enter the Advanced Calendar Service, which uses the Calendar API to manage your domains calendars (and I suspect is probably the correct way to go about managing your domains calendars). After you turn the calendar service on, you can do what your looking for simply like so:
function calendar(){
var cal = Calendar.Calendars.get('calendar#domain');
Logger.log(cal.summary);
};
Which will return the 'name' of the calendar. (Note: For primary calendars, the 'name' of the calendar is almost always the same as the calendar ID).