- April 12, 2024
- Posted by: Magdhal Smith
- Category: Power Apps
Introduction
In the dynamic landscape of productivity tools, Microsoft PowerApps stands out as a versatile platform for building custom applications and automating workflows. One common scenario within organizational settings involves the need to cancel or remove events from Outlook calendars swiftly and efficiently. In this blog, we explore how to cancel Outlook calendar events directly within PowerApps. The below code is designed for use within a Microsoft Power Apps context, involving operations with the Office 365 Outlook calendar. It performs two primary actions: setting a variable to reference a specific calendar and then deleting a selected calendar event from that calendar.
Add Existing Calendar Template
Add existing Calendar template in PowerApps.
![](https://sandbox.cittabase.com/wp-content/uploads/2024/04/Picture1.png)
Add a button to the Gallery and Name it as Cancel.
![](https://sandbox.cittabase.com/wp-content/uploads/2024/04/Picture2.png)
In the OnSelect property of the Cancel Button, we can set Calendar ID, using this Calendar ID we can Delete the Calendar Events.
Setting the Calendar ID
OnSelect property of the Cancel Button
Code: Set(MyCalendarID,LookUp(Office365Outlook.CalendarGetTables().value, DisplayName = "Calendar").Name);
- Set (MyCalendarID,…): This code uses the Set function to create (or update) a global variable named MyCalendarID. Global variables in Power Apps are accessible across all screens within the app.
- LookUp(Office365Outlook.CalendarGetTables().value,DisplayName = “Calendar”).Name
This function call is doing a few things:
- Office365Outlook.CalendarGetTables().value: Retrieves a list (value) of calendar tables available in the user’s Office 365 Outlook account.
- Lookup(…, DisplayName = “Calendar”): Searches through the retrieved list for a calendar whose display name matches Calendar.
- .Name: Extracts the Name property of the found calendar object. The Name is used by Office 365 Outlook APIs to uniquely identify calendars.
The entire line effectively finds the unique identifier (Name) for the calendar named Calendar and stores it in MyCalendarID, which can then be used in subsequent operations.
Deleting a Calendar Event
OnSelect property of the Cancel Button
Code: Office365Outlook.CalendarDeleteItemV2(MyCalendarID,CalendarEventsGallery.Selected.Id);
- Office365Outlook.CalendarDeleteItemV2(…): This function is a part of the Office 365 Outlook connector, which allows Power Apps to interact with calendar events in a user’s Outlook account. The CalendarDeleteItemV2 action is specifically used to delete a calendar event.
- MyCalendarID: This is the first parameter for the CalendarDeleteItemV2 function. It specifies from which calendar to delete the event, using the ID stored in the MyCalendarID variable from the first action.
- CalendarEventsGallery.Selected.Id: This expression specifies the second parameter for the CalendarDeleteItemV2 function, the ID of the event to delete. It assumes there is a gallery control in the app named CalendarEventsGallery, which displays a list of calendar events. .Selected refers to the currently selected item (event) in this gallery and extracts the unique ID of this selected event.
In summary, this code snippet first finds and stores the ID of a specific Outlook calendar named Calendar in a global variable. Then, it deletes an event, selected by the user from a gallery within the app, from this specific calendar.
Before cancelling the event
![](https://sandbox.cittabase.com/wp-content/uploads/2024/04/Picture3.png)
After cancelling the event
![](https://sandbox.cittabase.com/wp-content/uploads/2024/04/Picture4.png)
In conclusion, this approach offers a practical solution for managing calendar events within the Microsoft Power Apps environment, specifically integrating with Office 365 Outlook calendars. By setting a variable to reference a chosen calendar and enabling the deletion of selected events, the code enhances user productivity and efficiency in organizing schedules and managing appointments. This functionality streamlines workflow processes and improves user experience within the Power Apps ecosystem, demonstrating the versatility and effectiveness of leveraging Power Apps for calendar management tasks.
Please feel free to reach Cittabase for more information. Visit our blog for more topics on Microsoft PowerApps.