Blog
Outlook - How to add, edit, delete, and list Outlook calendar events
By integrating apps with Outlook calendars, we can create far more powerful apps, particaularly in the case of scheduling applications. This post describes how to integrate with Outlook through the Office 365 Outlook Connector Including tasks that include adding, editing, deleting, and searching Outlook calendar events.
- How to create a calendar entry
- How to search and list entries from a calendar
- How to edit a calendar entry
- How to delete a calendar entry
Introduction to Outlook Calendars
An instance of Outlook can contain multiple calendars. The screenshot beneath shows how there are three available calendars in my Outlook calendar - Birthdays, Calendar, and United Kingdom holidays.
Getting started - adding the Office 365 Outlook connector
To get started, the first step is to add the Office 365 Outlook connector to the app.
Getting a list of calendars
Once we add the Office 365 Outlook connector, the next logical step is to retrieve a list of available calendars. To retrieve a list of calendars, we call the Office365Outlook.CalendarGetTablesV2 method.
The formula beneath highlights how to retrieve a list of calendars and how to store the result in a collection called colCalendars.
ClearCollect(colCalendars,The return value from CalendarGetTablesV2 is an object called 'value' - this is a table that contains calendar details, such as the calendar name and unique id. The calendar id value is very important because we require this to identify the calendar when we add, edit, delete entries.
Office365Outlook.CalendarGetTablesV2()
)
Retrieving the Calendar ID for the current user
To retrieve the unique id of the user calendar and to store it in a variable called varUserCalendarId, we use the formula beneath. It's a good idea to add this formula to the OnStart property of an app for easy access. Alternatively, we can retrieve the calendar id prior to the point when we want to use the calendar.
Set(varUserCalendarId,
LookUp(Office365Outlook.CalendarGetTablesV2().value,
name="Calendar").id
)
Creating a simple calendar entry
Office365Outlook.V4CalendarPostItem(
varUserCalendarId,
"Calendar subject text",
"2021-11-01T04:00:00",
"2021-11-01T05:00:00",
"UTC"
)
- Table - this defines the calendar ID. The example here references the calendar id that's stored in varUserCalendarId.
- Subject - this defines the subject text that appears in the calendar entry.
- Start datetime - this defines the start date and time in string format.
- End datetime - this defines the end date and time in string format.
- Timezone - this defines the timezone.
Office365Outlook.V4CalendarPostItem(
varUserCalendarId,
"Ignite conference keynote",
Text(DateTimeValue("2021-11-02 17:00:00"),DateTimeFormat.UTC),
Text(DateTimeValue("2021-11-02 18:00:00"),DateTimeFormat.UTC),
"UTC"
)
Creating an all-day calendar entry
Office365Outlook.V4CalendarPostItem(
varUserCalendarId,
"Team meeting",
Text(Date(2021,11,03),DateTimeFormat.UTC),
Text(Date(2021,11,04),DateTimeFormat.UTC),
"UTC",
{isAllDay:true}
)
Creating a recurring entry calendar entry
Office365Outlook.V4CalendarPostItem(
varUserCalendarId,
"Re-occuring entry",
Text(Date(2021,11,03),DateTimeFormat.UTC),
Text(Date(2021,11,04),DateTimeFormat.UTC),
"UTC",
{isAllDay:true, recurrence:"daily",numberOfOccurences:3}
)
Creating a calendar entry with a reminder
Office365Outlook.V4CalendarPostItem(
varUserCalendarId,
"Calendar entry with reminder",
Text(Date(2021,11,03),DateTimeFormat.UTC),
Text(Date(2021,11,04),DateTimeFormat.UTC),
"UTC",
{isReminderOn:true, reminderMinutesBeforeStart:15}
)
Listing calendar entries
Office365Outlook.GetEventsCalendarViewV3(
varUserCalendarId,
Text(Date(2021,11,01),DateTimeFormat.UTC),
Text(Date(2021,11,30),DateTimeFormat.UTC)
).value
Subject, Start time, End time, Start time with time zone, End time with time zone,
Body, Is HTML, Response type, Response time, Id, Created time, Last modified time,
Organizer, Time zone, Series master id, iCalUId, Categories, Web link,
Required attendees, Optional attendees, Resource attendees, Location,
Importance, Is all day event?, Recurrence, Recurrence end date,
Number of occurrences, Reminder, Is reminder on, Show as,
Response requested, Sensitivity
Searching calendar entries
Office365Outlook.GetEventsCalendarViewV3(
varUserCalendarId,
Text(Date(2021,11,01),DateTimeFormat.UTC),
Text(Date(2021,11,30),DateTimeFormat.UTC),
{search:"SearchTerm"}
).value
Office365Outlook.GetEventsCalendarViewV3(
varUserCalendarId,
Text(Date(2021,11,01),DateTimeFormat.UTC),
Text(Date(2021,11,30),DateTimeFormat.UTC),
{'$filter':"contains(subject,'biz')"}
).value
Updating calendar entries
As a demonstration, here's the formula to update the first calendar entry on the 3rd November, where the subject text matches "Team meeting". This formula updates the subject text to "New Subject Text" and retains the existing start and end times. It also applies the body text to the calendar entry.
With({idCalendarEntry:
First(
Office365Outlook.GetEventsCalendarViewV3(
varUserCalendarId,
Text(DateTimeValue("2021-11-03 00:00:00"),DateTimeFormat.UTC),
Text(DateTimeValue("2021-11-03 23:59:59"),DateTimeFormat.UTC),
{search:"Team meeting"}
).value
)
},
Office365Outlook.V3CalendarPatchItem(
varUserCalendarId,
idCalendarEntry.id,
"New Subject Text",
idCalendarEntry.start,
idCalendarEntry.end,
{Body:"Updated calendar entry body text"}
)
)
Deleting calendar entries
The formula beneath shows how to delete the first calendar entry on the 3rd November, where the subject text matches "Team meeting".
With({idCalendarEntry:
First(
Office365Outlook.GetEventsCalendarViewV3(
varUserCalendarId,
Text(DateTimeValue("2021-11-03 00:00:00"),DateTimeFormat.UTC),
Text(DateTimeValue("2021-11-03 23:59:59"),DateTimeFormat.UTC),
{search:"Team meeting"}
).value
)
},
Office365Outlook.CalendarDeleteItemV2 (
varUserCalendarId,
idCalendarEntry.id
)
)
Conclusion
We can integrate apps with Outlook calendars through the Office 365 Outlook connector. This post highlighted the formula to carry out common tasks, including how to add, edit, update, list, and search calendar entries.- Categories:
- outlook