How To Populate Employee ID Of User From Azure AD In PowerApps

Problem

In many organizations, users from departments like Finance, HR, accounts, or payroll always refer employee ID for any process or transaction. That’s good practice because employee ID is always unique. User display names can be similar and email addresses can be difficult to memorize.

So, these end users always want employee ID to be part of all the processes, forms, notifications. They want employee ID to be populated automatically when they select the user from Person and Group field.

In PowerApps you can use Office365Users connector, use functions such as GetUserProfile, GetMyProfile, SearchUser; despite all these functions none of it returns employee ID property. It returns user resource with properties like display name, first name, last name, email, phone number, job title, address, country, city, state, etc.

So how to get the employee ID of a user from Azure AD into PowerApps?

Solution

Let’s first understand why Office365Users connector doesn’t return EmployeeId property. The user resource type in Azure AD doesn’t contain property called EmployeeId. But we can still synchronize employee ID from on-premises AD to Azure AD, the synchronization tools allow us to create such properties as extension property.

As the Employee ID is an extension property it’s not present in the default response schema of Office365User connector, but it's part of user resource in Graph API. That’s the reason we will be able to retrieve it using below method.

Create a FLOW with simple trigger and actions as shown below. Depending on where and how you want employee ID – you can choose the trigger. If you want the employee ID in PowerApps form, then choose PowerApps as trigger. If you want to save employee ID in the backend then you can use any list item event as a trigger.

How To Populate Employee ID Of User From Azure AD In PowerApps

  • First action is compose action, just to get the input data from PowerApps. You can create a variable as well if you want. This input would be email address of selected user.
  • Second action is Get User Profile action, in the search fields type “employeeId” as shown in above screenshot.
  • Third and last action is responding back to PowerApps, create text return parameter and set it to

outputs('Get_user_profile_(V2)')?['body/employeeId']

In the PowerApps, add reference to the FLOW and trigger it OnChange event of user combobox control as shown below, save the response in a variable.

I have added safe check, or you can say added validation to avoid FLOW calls with empty data. The FLOW will get called only when the specified control has valid user selected in it.

If(!IsBlankOrError(DataCardValue2.Selected), Set(selectedEmpID, GetEmployeeID.Run(DataCardValue2.Selected.Email).empid))

How To Populate Employee ID Of User From Azure AD In PowerApps

Set the variable as default value to EmployeeID field in the form.

How To Populate Employee ID Of User From Azure AD In PowerApps

Using above approach, we are able to get the employee ID of required user on-demand. So, the end user who is filling the form can see the employee ID populated within a second.

Check out above configuration in detail in this YouTube video.

Summary

So even if with Office365Users connector in PowerApps we are not able to get the employee ID, we can still populate it by making a call to FLOW which will indeed make use of same connector and returns back the employee ID data.

I hope this will help you guys. Thanks for reading.