Power Apps Show/Hide Button Based On The Current User

This Power Apps tutorial will help you to teach how to work with Power Apps Show/Hide Button Based On The Current User.

Also, we will see how to show or hide a Power Apps button if the current user contains a hardcoded email and if the current user is present in the SharePoint List.

Power Apps Show/Hide Button Based On The Current User

In this post, I will explain two ways to show or hide the Power Apps button based on the current logged-in user. Such as:

  1. Power Apps Show/Hide Button If Current User Contains a Hardcoded Email (With Single & Multiple Emails)
  2. Power Apps Show/Hide Button If Current User Present in the SharePoint List

Let’s have a look at the below image.

There are two images (Power Apps Canvas App). The first image contains four Buttons. Such as:

  • Home
  • Job Seekers
  • About
  • Admin

When the current logged-in user has Admin Role/Department, they can only view the Admin Button. If the current logged-in user has no Admin Role/Department or the current logged-in user is from any other department like HR, or IT, then the Power Apps Admin button will be invisible (refer to the second image).

Power Apps Show Hide Button Based On The Current User

Power Apps Show/Hide Button If Current User Contains a Hardcoded Email

Here, We will see how to show/hide the Power Apps button if the current user contains a hardcoded name (with single and multiple emails).

Hardcoded with a Single Email

  • In this example, the Power Apps Admin Button will be visible only to a single user (For Admin) that we will hardcode in the code. Other users can not see the Admin button until we specify the email in the code.
  • To do this, apply the code below on App’s OnStart property:
OnStart = Set(
    varUserEmail,
    User().Email
);
Set(varUserAdmin, 
varUserEmail = "Preeti@tsinfotechnologies.onmicrosoft.com");

Where,

  1. varUserEmail, varUserAdmin = Specify the variable names
  2. Preeti@tsinfotechnologies.onmicrosoft.com” = Provide the Admin email address (to whom the Admin button will be visible)
  • The value of the variable varUserEmail, which is retrieved by the User function, is the email address of the currently logged-in user.
  • The outcome is then saved in the varUserAdmin variable once we determine whether the Admin’s email address matches varUserEmail. The match value returns true, and the non-match value returns false.
Power Apps Show or Hide Button Based On The Current User
  • Next, go to the App under the Tree view -> Click on ellipses () -> Click on Run OnStart.
Show Hide Power Apps Button Based On The Current User
  • Then go to the Admin button and set its Visible property:
Visible = varUserAdmin

varUserAdmin = Provide the variable name that you have created

How to Show or Hide Power Apps Button Based On The Current User

This is how to work with Power Apps Show/Hide button hardcoded with a single email.

Hardcoded with Multiple Emails

Next, we will see how to work with Power Apps Show/Hide Button hardcoded with multiple emails.

  • In this example, we’ll hardcode many users (for admin) to be able to see the Power Apps Admin Button. Other users cannot see the Admin button until we specify the email in the code.
  • To work around this, apply the code below on App’s OnStart property:
OnStart = Set(
    varUserEmail,
    User().Email
);
Set(
    varUserAdmin,
    varUserEmail in [
        "Preeti@tsinfotechnologies.onmicrosoft.com",
        "Bijay@tsinfotechnologies.onmicrosoft.com"
    ]
);

Where,

  1. varUserEmail, varUserAdmin = Variable names
  2. Preeti@tsinfotechnologies.onmicrosoft.com“, “Bijay@tsinfotechnologies.onmicrosoft.com” = Enter the email addresses (to whom the Admin button will be visible)
Power Apps Show Hide Button Based On Current User
  • Next, go to the App under the Tree view -> Click on ellipses () -> Click on Run OnStart.
Show Hide Power Apps Button Based On The Current User
  • Go to the Admin button and set its Visible property:
Visible = varUserAdmin

varUserAdmin = Provide the variable name that you have created

PowerApps Show Hide Button Based On Current User

This is how to work with Power Apps Show/Hide button hardcoded with multiple emails.

Check out: Power Apps Button OnSelect [Complete Tutorial]

Power Apps Show/Hide Button If Current User Present in the SharePoint List

Here we will see how to show/hide the Power Apps button If the current user is in the SharePoint List.

  • I have a SharePoint Online List named Scheduled Events. This list has these many columns below:
ColumnsData types
TitleSingle line of text
LocationChoice [Pentagon. Decagon, Octagon, Nonagon]
DepartmentChoice [FINANCE Team, MARKETING Team, Admin, HR Team]
Event ManagerPerson
Start DateDate and time
End DateDate and time
  • Only if the user who is now logged in only has the Admin Department will the Power Apps Admin Button be shown. The Power Apps Admin button won’t be displayed to the currently logged-in user if they have other departments, such as MARKETING, FINANCE, etc.
Power Apps Show Hide Button If Current User Present in the SharePoint List
  • To achieve this, apply the code below on App’s OnStart property:
OnStart = Set(
    varUserFullName,
    User().FullName
);
Set(
    varIsAdmin,
    !IsBlank(
        LookUp(
            'Scheduled Events',
            And(
                'Event Manager'.DisplayName = varUserFullName,
                Department.Value = "Admin"
            )
        )
    )
);

Where,

  1. varUserFullName, varIsAdmin = Variable names
  2. User().FullName = This User function retrieves the current logged-in user details. To retrieve the user’s full name, I applied as User().FullName.
  3. Scheduled Events‘ = SharePoint List Name
  4. Event Manager‘ = SharePoint Person Column. As this column contains the user display name, I specified ‘Event Manager’.DisplayName. If this column contains the user email address, specify it as ‘Event Manager’.Email.
  5. Department = SharePoint Choice Column
  6. Admin” = Specify the Department value to whom the Admin button will be visible

Refer to the screenshot below.

Power Apps show hide button if current user is in sharepoint list
  • Then, go to the App under the Tree view -> Click on ellipses () -> Click on Run OnStart.
Power Apps Show Hide Button Based On The Current User From SharePoint List
  • Go to the Admin button and set its Visible property to the created variable:
Visible = varIsAdmin
PowerApps Show Hide Button Based On The Current User
  • Finally, Save, Publish, and Close the app. Reopen the app once again and play or Preview it. If the Current logged-in user is from the Admin department, only he/she can view the Admin button.
  • If the Current logged-in user is from any other department (like FINANCE, HR), he/she can not view the Power Apps Admin button.

This is how to work with Power Apps Show/Hide button if the current user is present in the SharePoint List.

Furthermore, you may like some more Power Apps Tutorials:

This Power Apps tutorial discussed how to work with Power Apps Show/Hide Button Based On The Current User.

Also, we learned the topics below:

  • How to show or hide a Power Apps button if the current user contains a hardcoded email (With Single & Multiple Emails).
  • Show or hide a Power Apps button if the current user is in the SharePoint List.
>