Auto Fill User Profile Details In PowerApps Forms

Scenario

If you are using PowerApps apps or SharePoint customized forms, then you might have come across a requirement where you need to auto-fill the currently logged-in user’s information in the form.

Solution

In this article, we will see how to auto-fill the information of the currently logged-in user in the form. If you are familiar with InfoPath forms, you might remember the userName() function. It is used to return the login name of the current user.

Similarly, in PowerApps, there is a User() function but it has only three properties, as shown below.

Auto Fill User Profile Details In PowerApps Forms

What if you want to get the information like JobTitle, Department, Photo of the logged-in user? Yes, this is also easily possible in PowerApps. You need to make use of the Office 365 Users connector in your app.

Go to your App and open the View tab >> Data Sources >> Add Data source. Search for Office 365 Users and add it.

Auto Fill User Profile Details In PowerApps Forms

Now, there are plenty of functions and tons of properties you can access using Office365Users class/function. You can even get the information of the manager or subordinates of the logged in user.

Let’s check a few examples.

Get department of current logged in user

Office365Users.UserProfile(User().Email).Department

Get Job Title of current logged in user

Office365Users.UserProfile(User().Email).JobTitle

Auto Fill User Profile Details In PowerApps Forms

You can get the user profile information of any user by providing the email-id of that user to UserProfile function.

Let’s see how to apply these values to a control in the form. The values should be fetched from the connector only when the form is opened in New mode. Otherwise, it should show the saved value from the database.

If(Form1.Mode = FormMode.New, Office365Users.UserProfile(User().Email).Department ,Parent.Default)

If(Form1.Mode = FormMode.New, Office365Users.ManagerV2(User().Email).displayName ,Parent.Default)

Auto Fill User Profile Details In PowerApps Forms

I hope this helps. Thank you.


Similar Articles