Check If A User Exists In Organization Through Power Apps Office 365 Users

Yesterday, I implemented a client task: how to avoid saving duplicate employee names in the SharePoint list through Power Apps.

In that case, I was required first to check whether the user existed in the organization through a Power Apps connector called Office365Users. If the user/employee name exists in the Office 365 users, it will appear in the Combo box; otherwise, it won’t.

In this article, I will explain how to check if a user exists in organization through Power Apps Office 365 Users. Also, we will discuss how to check if a user exists from a SharePoint list person field using Power Apps.

Check If A User Exists In Organization Through Power Apps Office 365 Users

Maybe you are wondering about it after seeing the screenshot below! Yes, it’s the correct picture only.

Here, there is a Power Apps Text input control and a Button. When the user provides any Employee Email address (from Office 365) and taps on the CHECK button, it will return a true or false value based on the user’s existence.

In Power Apps Office 365 Users, to check whether a user exists, it returns a boolean value of “true” if the user doesn’t exist and “false” if the user does.

Check If A User Exists In Organization Through Office 365 Users

1. Add a Text input and a Button control in the app to achieve this. Now, create a variable on the Button’s OnSelect property as: [Also, you can provide the code below either the App’s OnStart or the Screen’s OnVisible property]

Set(
    varValidUser,
    IsEmpty(Office365Users.SearchUser({searchTerm: txtEmployeeEmail.Text}))
);

Where,

  • varValidUser = Variable Name
  • txtEmployeeEmail = Text input control name

NOTE:

Ensure to add the Power Apps Office365Users connector to the app before applying the above code to avoid any errors.

Check If A User Exists In Organization Through Power Apps Office 365 Users

2. Insert a Label control and place it at the top of the text input box. Provide the variable name on its Text property as:

"User Exists - " & varValidUser
How to Check If A User Exists In Organization Through Power Apps Office 365 Users

3. Save, publish, and preview the app. In the text box, enter any Employee Email ID (from Office 365) and click CHECK. Depending on the employee’s existence, the app will return either a true or a false value. If it returns false, then the user exists; if it returns true, then the user does not exist.

Power Apps Check If A User Exists In A SharePoint List Person Field

Next, let’s discuss how to use Power Apps to check if a user exists in a SharePoint Person field.

1. I have a SharePoint list named Employee Survey Form, with all the fields below and a Person field.

ColumnData type
Employee Full NamePerson
Employee EmailSingle line of text
Contact NumberNumber
Current LocationChoice [Australia, Brazil, Canada]
AgeNumber

Refer to the image below.

Power Apps Check If A User Exists From A SharePoint List Person Field

2. In Power Apps, an Edit form is connected to this SharePoint list. The form contains the Employee Full Name (Combo box control) and all the active users from the Office 365 account.

When a user selects an employee name from the Combo box, it checks whether the selected employee is present in the SharePoint list. If it does, the Power Apps form will not be submitted. If the employee chosen from the combo box does not exist, the survey form will be allowed to be submitted.

Have a look at the GIF below:

Power Apps Check If A User Exists In A SharePoint List Person Field

3. First, select the Employee Full Name Combo box Data card value and apply the formula below on its Items property:

Filter(
    Office365Users.SearchUser(
        {
            searchTerm: DataCardValue12.SearchText,
            top: 999
        }
    ),
    AccountEnabled = true
)

Where,

DataCardValue12 = Employee Full Name Combo Box Data Card Name

The above code helps filter and search all the top 999 users from the Office 365 account and displays only the active users.

Power Apps Check If A User Exists In A SharePoint Person Column

4. To check whether the combo box selected employee name exists or not, copy and paste the code below on the SAVE Button’s OnSelect property:

If(
    CountRows(
        Filter(
            colEmployeeSurveys,
            'Employee Full Name'.DisplayName in DataCardValue12.Selected.DisplayName
        )
    ) > 0,
    Notify(
        "Please Select Other Employee Name, Your Selected Name Already Existed in List",
        NotificationType.Error
    ),
    SubmitForm(Form3);
    Notify(
        "Your Survey Has Been Submitted Successfully",
        NotificationType.Success
    );
    ResetForm(Form3)
)

Where,

  • CountRows = This function helps to count the total number of items from the collection
  • colEmployeeSurveys = Power Apps Collection Name that contains all the data from the existing SharePoint list
  • ‘Employee Full Name’ = SharePoint Person Field
  • DataCardValue12 = Employee Full Name Combo box Data Card Name
  • Form3 = Edit Form Name
How to Check If A User Exists In A SharePoint List Person Field using Power Apps

5. Finally, save, publish, and preview the app. Try to enter the details or the employee’s full name that already exists in the SharePoint list.

Once you tap the SAVE button, an error notification will appear in the top left corner, as shown below. The message says, “Please Select Other Employee Name, Your Selected Name Already Existed in List.”

PowerApps Check if User Exists In SharePoint Person Column

These are the two examples to check if a user exists in an organization with Power Apps. Such as;

  • Check if an employee exists through Power Apps Office 365 Users
  • Check if a user exists in a SharePoint Person column using Power Apps

I hope this article found helpful.

Additionally, you may like some more Power Apps tutorials:

Power Apps functions free pdf

30 Power Apps Functions

This free guide walks you through the 30 most-used Power Apps functions with real business examples, exact syntax, and results you can see.

Download User registration canvas app

DOWNLOAD USER REGISTRATION POWER APPS CANVAS APP

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