Canvas, PowerApps, Uncategorized

Canvas App: Office365Users.Search UserV2 not working, but V1 does

Scenario:

Currently, I am working on the New Environment Request app. As a part of the solution, we add the environment business Owner which as we know is different from the Owner field populated by default with the name of the user who physically spins the environment.

Therefore, on the form, we allow a user to pick an Owner from the list of users.

Solution:

We will use Office 365 Users standard connector: https://learn.microsoft.com/en-us/connectors/office365users/

It has a SearchUser method and we will work with it. I suggest watching Shane Young’s video which I put at the bottom of the article. It explains everything in detail.

For my own reference, I put the steps below. Some things are a bit different as I use the most recent controls and connectors.

As I followed the video, I started with version 1 of the method to simply get it working. Then I moved to V2 as we always try to use the latest available API, methods, and connector versions to ensure we don’t have to update our formulas too soon.

Office365Users.SearchUser (V1)

I put 2 combo boxes on the form and marked them to make it clear.

I added a new data source. Populating data from the Office 365 Users connector.

I linked the data source to the first combo box.

I used a formula called the SearchUser method to populate Items.

On the Properties panel for Fields Layout, I selected Double to display not only Display Name but also UPN field to differentiate users with multiple accounts. I used Display Name as a search field.

If you watched Shane’s video, he is using an extra Input control for the search. I don’t. My formula looks like this, I pass the search text as a parameter to filter the dataset:

Office365Users.SearchUser({searchTerm:searchUserV1Cbb.SearchText})

Use the following settings to make it look cleaner and enable searching of course.

The result looks nice! As you could see, there are multiple accounts for Olena so having a second row with UPN really helps.

OK. It’s done! Let’s move to V2. What could possibly go wrong!

Office365Users.SearchUser (V2)

Copy/paste. Changing the method to SaerchUserV2…

Office365Users.SearchUserV2({searchTerm:searchUserV2Cbb.SearchText})

I don’t like the red cross icon. Do you?

Also, my fields! There are no fields available for selection. What’s going on?!

Well… TDH it took me a bit of a time to figure it out. The Checker doesn’t say anything helpful. But the actual red cross icon hover text does!

Looks like the format of the result retrieved by the method is changed. Let’s have a look at it closer!

The method retrieves a Record. We need a Table instead. The Table required is stored in value.

Now it’s all easy! We correct the formula to give us the Table like in the code below.

Office365Users.SearchUserV2({searchTerm:searchUserV2Cbb.SearchText}).value

The red cross icon disappeared! Good!

Now we could select display fields and a search field.

And it works in an awesome way!

Shane Young Appreciation Note

I would like to express my respect and admiration for Shane Young for doing so much for the community. His video tutorial saved me a great amount of time and effort.

PowerApps Office 365 User Search

1 thought on “Canvas App: Office365Users.Search UserV2 not working, but V1 does”

Leave a comment