How to Search for Anyone within the Organization in Power Apps

When we design solutions for a department application or even an enterprise application using Power Apps, sometimes we need to provide the capability for selecting anyone within the organization to send an email notice or to initiate a working process. Power Apps does provide a standard function for this under the Office 365 Users connector:

This works fine for a small organization but will eventually fail when applied in a large enterprise. This is because it can only return the first 1000 users from the Microsoft active directory, so you will not be able to find users beyond the top 1000.

There are two workarounds to mitigate this limitation.

Method 1: Make Use of the SharePoint List Person Column

This is a simpler but partial solution if you are using SharePoint List as the database and the process involves writing the selected user data into the list.

When creating the List, you can create a data column with the type Person. By doing this, you allow a JSON object containing Office 365 user profile to be stored in this data field.

After this, you can go to Power Apps and create a Forms control and select the List you have created as the data source. Power Apps will automatically create a Combo Box input control to match the Person column, and this will allow you to select anyone within the organization.

Method 2: Make Use of the searchTerm Parameter

The standard Search for Users function does allow us to conduct a key word search to filter the contact list before returning the results. We can leverage this to build a more complete and versatile solution.

Step 1: add Office365Users connector into the app data source

Step 2: create a simple Text Input object

Step 3: create a Combo Box object and in its Items property, write

Office365Users.SearchUserV2({searchTerm:Trim(TextInput1.Text)}).value

Trim() is just a simple function to remove all spaces from a string of text except for single spaces between words, so to make the searchTerm more standardized. TextInput1 is the name of the object created in step 2, and you can replace it with the actual object name in your app.

Now you should be able to search for users beyond the top 1000 items by specifying key word in the Text Input field.

You can even provide second key word in the Combo Box to narrow down the search results.

Leave a Comment