What’s your chosen method for getting logged-on user information in a canvas app? There’s 2 popular ways – the User function and via the Office 365 Users connector.
Table of Contents
ToggleUser function
The User function can retrieve the logged-on users Full Name, Email and Photo:
Seems straight forward enough, doesn’t it?
But wait!!
As good as it might appear on the surface, the Microsoft documentation says the outputs may not match the current user’s information in Microsoft 365 or other services:
You don’t have to look too far to find evidence of this either (here and here being such examples). I believe the outputs of the User function comes from the ‘Users’ table in the CDS, which is synced data from Office 365. However, in my experiences of using this I’ve found mismatches with user names, emails and user principal names, or sometimes the user isn’t even found. There is a workaround for mismatches by using the Lower function; to avoid that or any of the above, I’ve defaulted to use the ‘Office 365 Users‘ connector instead.
Office 365 Users connector
Here’s why it’s better and safer to use this connector to get logged-on user information:
** It’s looking at your Office 365 user profile, which is tied to your company’s Active Directory. Active Directory should be sole version of truth for user data.
** Does your company have other third party systems you use? Chances are they’ll be implementing Single Sign On and to do that, user information syncs with Active Directory. That means any filtering of user information in other systems will be far more accurate if using this method.
** The outputs are considerably richer in information. The Office 365 profiles can hold other pertinent information, such as Department or Line Manager, the latter being awesome for automating escalations or approvals. It opens up more possibilities for conditional visibility, automations and other cool things.
** The connector exposes lots of other API endpoints, such as searching for other users or getting your direct reports.
** When trying to retrieve user information in Power Automate, what connector do we typically use? The Office 365 Users connector. Using the same in Power Apps is therefore a more consistent approach.
Configuration and approach
I’ll outline the steps and my approach below in this section.
Firstly add the Office 365 Users connector to your app:
Then, in the OnStart property for the app, I’ll add the following Power Fx to store the logged-on users information and profile image. Doing it this way means you only call the API once per session.
/*
Set global variables for logged-on users M365 profile details
*/
Set(
gvUserProfile,
Office365Users.MyProfileV2()
);
Set(
gvUserProfileImg,
Office365Users.UserPhotoV2(gvUserProfile.mail)
)
NOTE: there are 2 versions of each. Always opt for the latest version – in this instance that’s the V2 options.
You can now use the variable in any of the usual ways in your app. You can see from the IntelliSense the breadth of data available:
If you want unrivalled accuracy for user data in the Power Platform, it’s the Office 365 Users connector all the way.
Great new blog Craig, When are you going to start a YouTube channel?
I already have a channel… with 1 video on it! I’ll make more use of it in the future, watch this space.
Great article, Craig. I’ve often resorted to the User() in PowerApps but looks like using the O365 User connector is a better option. Will be using this going forward.
Nice article, this is very useful to know!
I was wondering how you would create a button that could look at a text input field to then search using the Office365users connector for an account using the Mail.Nickname value.
It would then need to obtain that Office365 users DisplayName, TelephoneNumber and Department retaining that information so It can then be inputted into view only Text Inputs in a form that could then be patched to a SharePoint List
Do you have any idea where I could learn how to do things like that don’t know where to start with Microsoft Power Apps courses other than the fundamental ones?
I tend to be careful about replicating Entra data into SP lists or other data sources, as you’re effectively duplicating the data so end up with multiple versions of the truth. That said, getting user information is quite easy from text input controls, you can effectively build your own people picker – here’s an example: https://www.youtube.com/watch?v=jd4lIXOC65E&t=227s&ab_channel=GiulianoDeLuca
You can then reference the selected item to get the users data you need.