Remove Guest Users From Power Apps Combo box

While testing a Power Apps Survey form, I noticed an issue where the Person combo box control allows users to select external guests (from Office 365 AD) when submitting the form. And then I realised that it’s not the correct approach, where someone can accidentally pick any guest user and submit the form.

To overcome this issue, we need to display the internal user names (excluding guest users) from the Office 365 Active Directory in the Power Apps Combo box.

In this article, I will show you the various ways to remove guest users from Power Apps Combo box control. Additionally, we will discuss how to remove external guests and display only active users in a Power Apps Combo box control with examples.

Remove Guest Users From Power Apps Combo box

In the screenshot below, you can see in the first image how all Office 365 users, including external guest users, are displayed. After removing all guest users from the combo box, it displays only internal user names, as shown in the second image.

Remove Guest Users From Power Apps Combo box

So let’s get started!

I have the SharePoint list below (Employee Survey Form) that contains various columns with different data types. Additionally, there is a Person field called Employee Full Name.

Remove Guest Users From Power Apps Combo box control

In Power Apps, there is a Modern Edit form that contains all these fields, along with the person column (Employee Full Name).

remove external user from Power Apps Combo box

Earlier, I provided the code below (in the Combobox Item’s property), which allows us to see all Office 365 users in the combo box control.

Office365Users.SearchUser({searchTerm: DataCardValue9.SearchText})
Remove Office 365 guest users from Power Apps Combo box

After that, when I previewed the app and expanded the combo box, it displayed all the Office 365 users, including the external guest user names.

remove external users from Power Apps Combo box

Now I would like to remove all external guest users and display only internal users in the Combo box control.

To do this, follow the different approaches below:

Formula – 1: [Filter out Guest users]

Most guest users contain #ext# in their UserPrincipalName. We can filter those out by using the code below: (apply this code to the Employee full name Combobox datacard Items property)

Filter(
    Office365Users.SearchUser({Top: 200}),
    Not(
        "#ext#" in Lower(
            Coalesce(
                UserPrincipalName,
                Mail,
                ""
            )
        )
    )
)
Delete guest users from Power Apps Combobox

Now, if you preview the app and expand the combobox, it won’t show any guest users.

Formula – 2: [Improve Performance with Collections]

The best practice is to use a Power Apps Collection. We can filter the external users inside a collection and then bind the collection to the Combo box control.

Apply the code below either on the App’s OnStart property and the Screen’s OnVisible property:

ClearCollect(
  colInternalUsers,
  Filter(
    Office365Users.SearchUser({Top: 200}),
    Not("#ext#" in Lower(Coalesce(UserPrincipalName, Mail, "")))
  )
);

colInternalUsers = Collection name

Power Apps Combo box remove Office 365 guest users

Next, select the Employee name Combo box data card value and bind its Items property to the collection, i.e., colInternalUsers.

Remove Office 365 external users from Power Apps Combo box

Finally, refresh the app, and you can see all the external guest users have been removed from the Power Apps Combobox control.

Formula – 3: [Remove Office 365 Guest Users & Show Only Active Internal Users]

In some cases, after removing guest users from the Power Apps Combo box, it still displays all internal Office 365 users, including inactive ones.

I would now like to filter the list further so that the Combo box shows only active internal users, excluding both guest and inactive accounts.

To achieve it, set the code below on the Combo box Datacard’s Items property:

Filter(
    Office365Users.SearchUser(
        {
            searchTerm: DataCardValue9.SearchText,
            top: 999
        }
    ),
    AccountEnabled = true && Not("#ext#" in Lower(UserPrincipalName))
)

Where,

AccountEnabled helps to retrieve all the active users from Office 365.

Delete Guest Users Power Apps Combo Box

Once you preview the app and expand the Combo box, it will only show the active internal Office 365 users.

I hope this article helped you understand how to remove Office 365 guest users from the Power Apps Combo box control, along with various examples.

Also, you may like some more Power Apps tutorials:

>

Build a High-Performance Project Management Site in SharePoint Online

User registration Power Apps canvas app

DOWNLOAD USER REGISTRATION POWER APPS CANVAS APP

Download a fully functional Power Apps Canvas App (with Power Automate): User Registration App

Power Platform Tutorial FREE PDF Download

FREE Power Platform Tutorial PDF

Download 135 Pages FREE PDF on Microsoft Power Platform Tutorial. Learn Now…