cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
k3rnel-pan1c
Level: Powered On

Combo Box o365 User Search

Hi all,

 

I'm working on a PowerApp where I use a Combo Box connected to O365 Users.

The idea is to have this field named "Collaborators" where you can select one or more usernames.

This is after saved into a Sharepoint List with some other data and viewed from a Gallery in the PowerApp.

 

Everything up to this point works perfectly.

 

What I want to accomplish now is create an edit view. I want to auto populate the Combo Box with the user names selected previously and have the option to select more users or remove the ones already selected.

 

Combo Box:

Items = Office365Users.SearchUser({searchTerm:ComboBox_Coll.SearchText}).DisplayName

DefaultSelectedItems = Office365Users.SearchUser({searchTerm: Parent.Default}).DisplayName

This solution only works if I select one User, when I have multiple users selected nothing works, the problem seems to be that the usernames are comma separated in one single string.

 

Any Idea on how can I fix this?

 

Thanks.

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Community Support Team
Community Support Team

Re: Combo Box o365 User Search

Hi @k3rnel-pan1c,

 

Please take a try to set the DefaultSelectedItems property as below:

ForAll(Split(Parent.Default,","),First(Office365Users.SearchUser({searchTerm:Result})).DisplayName)

Doing it in this way should make the default selected items showing out correctly.

 

The issue here is the Office365Users.Search() would return a table schema, if the search string matches, we need to get the first record from it, then the forAll function would combine each records into a proper table.

 

Regards,

Michael

Community Support Team _ Michael Shao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
9 REPLIES 9
Microsoft Employee

Re: Combo Box o365 User Search

Hello,

 

As you mentioned, the searchTerm does not support multiple values. You can work around that issue by using the "Filter" formula but there's catch - you may get inacurate data if the total number of users is greater than the connection row limitation (500 items by default which can be increased up to 2,000 from app settings). So, if the total number of users in your  org is less than 500 (or 2,000) then you can use the following formula:

Items=Filter(Office365Users.SearchUser({searchTerm:""}), DisplayName in Split(Parent.Default,","))

If the Parent.Default is a table (not a comma-separated string) then you can ommit the Split function. 

k3rnel-pan1c
Level: Powered On

Re: Combo Box o365 User Search

Thank you for your help.

 

This formula does not work unfortunately, from my test environment I created a plain textbox where I can see the usernames that should appear as already selected in the combo box but nothing gets selected.

 

Curious thing, if I add any letter between the quotes in the searchTerm that belong to any username in parent.default I get the very first selected in the combo box.

 

ex.

parent.default contains "username1,username2,username3"

 

Filter(Office365Users.SearchUser({searchTerm:"u"}), DisplayName in Split(Parent.Default,","))

combo box shows username1 only selected.

 

 

I might need to re-think my whole strategy to accomplish this.

Seems that Office365Users.SearchUser only returns usernames based on just one single specific criteria.

Microsoft Employee

Re: Combo Box o365 User Search

The issue you described is most likely because your ComboBox control does not allow multiple selections (which is not the default setting). Please make sure that YourComboBoxControl.SelectMultiple property is set to true.

k3rnel-pan1c
Level: Powered On

Re: Combo Box o365 User Search

Nope, that value is set to true, that is how I can select multiple users in the very first part where I create the new sharepoint List entry.

The problem is after when I want to edit the entry by re-populating the combobox with my previous selection.


Microsoft Employee

Re: Combo Box o365 User Search

Have you tried to remove the "Split" from the formula?

Filter(Office365Users.SearchUser({searchTerm:"u"}), DisplayName in Parent.Default)
k3rnel-pan1c
Level: Powered On

Re: Combo Box o365 User Search

I did, I even tried to add manually a list of usernames

["username1","username2","username3"]

but nothing shows up in the combobox.

 

I can search and select users from the dropdown but I can't force them in with a formula. 

k3rnel-pan1c
Level: Powered On

Re: Combo Box o365 User Search

This is strictly related to the Office365Users.SearchUser() formula.

 

In the same form I have another combobox that takes its items from a sharepoint list that works like this:

Items = ListName

DefaultSelectedItems = Filter(ListName.Title, Title in Parent.Default)

*"Title" is the name of the column in my List

 

and this works perfectly no issues at all.

Highlighted
Community Support Team
Community Support Team

Re: Combo Box o365 User Search

Hi @k3rnel-pan1c,

 

Please take a try to set the DefaultSelectedItems property as below:

ForAll(Split(Parent.Default,","),First(Office365Users.SearchUser({searchTerm:Result})).DisplayName)

Doing it in this way should make the default selected items showing out correctly.

 

The issue here is the Office365Users.Search() would return a table schema, if the search string matches, we need to get the first record from it, then the forAll function would combine each records into a proper table.

 

Regards,

Michael

Community Support Team _ Michael Shao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
k3rnel-pan1c
Level: Powered On

Re: Combo Box o365 User Search

YES!

Thank you! This works as I wanted ( for some reason though I get with the usernames also the very first element of the O365 user list selected, but I'll see if I can fix this myself).

 

Really appreciate your help, I tried to use ForAll with a similar formula missing the "First".

 

all the best!