The problem with LookUp
It is a pretty common use case to lookup users (using the LookUp function), especially the current logged in user, to get more details like their department or job title. Sometimes the function returns blank which is obviously incorrect. Let's look at why this happens and what the resolution is.
Problem happens when users have more than one email aliases. For example, if you want to send me an email to my Hitachi account:
- hbhatia@hsdyn.com
- hbhatia@hitachisolutions.com
The way to lookup a user is:
LookUp(
Users,
'Primary Email' = locUserPrincipalName
)
where locUserPrincipalName is
User().Email
or from a gallery for which the Items property is set to
Office365Users.SearchUser({searchTerm: txtTextInput_4.Text})
galUsers.Selected.UserPrincipalName
Fixing the issue
The way to fix this is to make sure you compare the email with both the user principal name and primary email. So modify the lookup function this way to make it work:
LookUp(
Users,
'Primary Email' = locUserPrincipalName || 'User Name' = locUserPrincipalName
)
Summary
In order to ensure that your user lookup works perfectly, make sure you compare the user's email (from the User() function or Office365Users.SearchUser() function) to both the 'User Principal' and 'Primary Email' fields of the Users table.
Navigating user lookups in Power Apps can initially seem complex, but this guide shines a light on the pathway, clarifying the differences between the Office 365 Users connector and Microsoft Dataverse. The inclusion of best practices and potential pitfalls, like delegation, is invaluable. As a reader, I feel equipped and empowered to handle user lookup scenarios with greater confidence and efficiency.