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:
- Power Apps Show/Hide Button If Current User Contains a Hardcoded Email (With Single & Multiple Emails)
- 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 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,
- varUserEmail, varUserAdmin = Specify the variable names
- “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.
- Next, go to the App under the Tree view -> Click on ellipses (…) -> Click on Run OnStart.
- Then go to the Admin button and set its Visible property:
Visible = varUserAdmin
varUserAdmin = Provide the variable name that you have created
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,
- varUserEmail, varUserAdmin = Variable names
- “Preeti@tsinfotechnologies.onmicrosoft.com“, “Bijay@tsinfotechnologies.onmicrosoft.com” = Enter the email addresses (to whom the Admin button will be visible)
- Next, go to the App under the Tree view -> Click on ellipses (…) -> Click on Run OnStart.
- Go to the Admin button and set its Visible property:
Visible = varUserAdmin
varUserAdmin = Provide the variable name that you have created
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:
Columns | Data types |
---|---|
Title | Single line of text |
Location | Choice [Pentagon. Decagon, Octagon, Nonagon] |
Department | Choice [FINANCE Team, MARKETING Team, Admin, HR Team] |
Event Manager | Person |
Start Date | Date and time |
End Date | Date 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.
- 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,
- varUserFullName, varIsAdmin = Variable names
- User().FullName = This User function retrieves the current logged-in user details. To retrieve the user’s full name, I applied as User().FullName.
- ‘Scheduled Events‘ = SharePoint List Name
- ‘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.
- Department = SharePoint Choice Column
- “Admin” = Specify the Department value to whom the Admin button will be visible
Refer to the screenshot below.
- Then, go to the App under the Tree view -> Click on ellipses (…) -> Click on Run OnStart.
- Go to the Admin button and set its Visible property to the created variable:
Visible = varIsAdmin
- 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:
- How to Show Hide Power Apps Label Control On Button Click
- PowerApps show hide fields based on Yes/No column
- How to Hide Top Navigation Bar in Power Apps
- Power Apps Filter Gallery By Date [With Examples]
- Power Apps Gallery Control Examples Download [20 Various Real Scenarios]
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.
I am Bijay a Microsoft MVP (10 times – My MVP Profile) in SharePoint and have more than 17 years of expertise in SharePoint Online Office 365, SharePoint subscription edition, and SharePoint 2019/2016/2013. Currently working in my own venture TSInfo Technologies a SharePoint development, consulting, and training company. I also run the popular SharePoint website EnjoySharePoint.com