is it possible to get Calendar event updates and new events with a calendar trigger. so, that only updates and new events are pulled. and then the properties (description, start date, end date, etc..) is pasted in the google sheet using app-scripts. I am an app-script novice.
is it possible to get Calendar event updates and new events with a calendar trigger. so, that only updates and new events are pulled. and then the properties (description, start date, end date, etc..) is pasted in the google sheet using app-scripts. I am an app-script novice.
Share Improve this question asked Feb 10 at 19:36 user3158459user3158459 551 silver badge4 bronze badges 2- Yes, this is possible with the help of Google Calendar Events and CalendarAPI. However, please keep in mind that StackOverflow is not a free coding service. You should at least try and do some research and then only ask about the things where you got stuck as the community is only here to guide you. Also, you may need to provide your desired output as you have stated in your post that you are gonna log the updates of the events. – PatrickdC Commented Feb 10 at 20:30
- You may want to use the concept in this post as the OP has already posted a working script with a calendar event based trigger. You only need to study some parts of the script posted. If you get stuck somewhere, you may return to this post and modify your question. – PatrickdC Commented Feb 10 at 20:33
1 Answer
Reset to default 0CalendarUpdate Trigger
After I create the trigger I close the spreadsheet that contains it and then reopen it and I find that it will run immediately after each edit. I have the timeMax and timeMin to look for events that are between 1 and 3 days after the current date. You can set it up as you wish. I chose a timeMin and timeMax to minimize the number of possible event.
Trigger Function:
function onCalendarUpdate1(e) {
const ps = PropertiesService.getScriptProperties();
Logger.log(JSON.stringify(e))
const nst = JSON.parse(ps.getProperty("CalUpdate")).nextSyncToken;
const cid = gobj.globals.emailpriv;//mycalendar id
const dt = new Date();
const min = (nst != null) ? new Date(dt.getFullYear(), dt.getMonth(), dt.getDate() + 1).toISOString() : null;
const max = (nst != null) ? new Date(dt.getFullYear(), dt.getMonth(), dt.getDate() + 3).toISOString() : null;
if (e.calendarId == cid) {
let events = Calendar.Events.list(cid, { timeMax: max, timeMin: min, nextSyncToken: nst });
ps.setProperty("CalUpdate", JSON.stringify(events))
}
}
Display Update Function:
function displayLastUpdate() {
const ss = SpreadsheetApp.getActive();
const ui = SpreadsheetApp.getUi();
const ps = PropertiesService.getScriptProperties();
const lu = ps.getProperty("CalUpdate");
ui.showModelessDialog(HtmlService.createHtmlOutput(`<textarea rows="12",cols="100">${lu}</textarea>`).setWidth(1200).setHeight(550), "Last Update Object")
}
Just displays the object returned which is stored in the PropertiesService in the trigger handler function.
Read the follow link carefully:
- Calendar Event Update