How to: Get default Outlook calendar of user in Power Apps

How to: Get default Outlook calendar of user in Power Apps

Intro

When you create an app, you want to make sure it’s working for everyone. Depending on the language of the user, the default calendar is named differently. So using the following code may result in unwanted errors.

LookUp(
    Office365Outlook.CalendarGetTablesV2().value,
    DisplayName = "Calendar"
)        


Solution

In an ideal scenario, you'd be able to automatically retrieve the default calendar regardless of its name. Good news: you can! Based on the documentation for the Office 365 Outlook connector, I discovered that the orderBy query relies on the Microsoft Graph. With a bit more digging, I found that every calendar has an "isDefaultCalendar" property. By using orderBy, you can prioritize the results and ensure the default calendar appears at the bottom. From there, you can store the result, for example in a variable, and dynamically determine the default calendar.


Copy the code

Add the following code to your App.OnStart. Now, you can use the global variable "Var_UserDefaultCalendar" throughout your app and access the default Outlook calendar properties.

Set(Var_UserDefaultCalendar,
    Last(
        Office365Outlook.CalendarGetTablesV2({orderBy: "isDefaultCalendar"}).value
    )
)        


References

Microsoft Power Platform — Office 365 Outlook

Microsoft Graph — List calendars

要查看或添加评论,请登录

Jeremy Levoye的更多文章

社区洞察

其他会员也浏览了