cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted

Restricting navigation to certain screens with an "IF" statement and PeoplePicker column from a SharePoint list

Hello,

I am looking to restrict access to a manager page within my powerapps application. I am wanting to do so by referring to a people picker column I have in a SharePoint list that hosts all the manager's information.

I am wanting to do so by doing something like this on visible property of a label:

If(Datasouce.ManagerPicker.Email = User().email, true, false)

OR

I have explored the option of trying something similar on the OnSelect property:

If(Datasource.ManagerPicker.Email = User().email, Navigate(managerPage),
                                                            Notify("You don't have permission to navigate to that page.", Error))

I am aware that this can be done if I type in a specific email address like so:

If(User().Email = "manager'sEmailAddress", navigate(managerPage), Notify(Error message)

I am trying to avoid that at all costs because there are several managers within the org. and if they change, I will have to manually change the syntax each time. This is why referring to the people picker column would be much easier.

Thanks for any assistance!

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Community Support
Community Support

Re: Restricting navigation to certain screens with an "IF" statement and PeoplePicker column from a SharePoint list

Hi  @caleb_abernathy ,

 

I made a test based on @mdevaney 's code, it works well for your case.

I put code '!IsBlank(LookUp('CTP - Processing','ManagerPicker-Test'.Email = User().Email))' to Visible of button directly, the button only be visible when I was in the SharePoint list person column, If I remove myself from the list and refresh the SP list connection, the button becomes invisible.

Snipaste_2020-04-02_13-57-30.pngSnipaste_2020-04-02_13-57-24.png

Could you please create a new canvas app to try again?

Sik

View solution in original post

8 REPLIES 8
Highlighted
Super User
Super User

Re: Restricting navigation to certain screens with an "IF" statement and PeoplePicker column from a SharePoint list

@caleb_abernathy 
Create a SharePoint list called 'Managers List'.  It should have a single column called 'Manager' which is a People column.  Add a new line for each manager that should be one the list.  Do not allow multiple values in a single field.

 

Then put this code in the OnStart property of your app.

Set(isManager, !IsBlank(LookUp('Managers List', Manager.mail = User().Email)))

 
Now you can use this code in the Visible property of your go to Manager screen button.

isManager

 

---
Please click "Accept as Solution" if my post answered your question so that others may find it more quickly. If you found this post helpful consider giving it a "Thumbs Up."

Highlighted

Re: Restricting navigation to certain screens with an "IF" statement and PeoplePicker column from a SharePoint list

Thanks for the quick response!

I set the onStart property of my app to: 
"Set(isManager, !IsBlank(LookUp('CTP - Processing','ManagerPicker-Test'.Email = User().Email)))"
And the visible property of the label to: "isManager"

 

Unfortunately, I had someone who wasn't on the manager list try to sign in and they can still see the lable.
Do I need to be more specific when it comes to setting the isManager variable?
Maybe someone denoting if it is true of false within the syntax? Because, right now, it appears that it is returning true for all users for some reason. 

Thanks!

 

 

Highlighted
Super User
Super User

Re: Restricting navigation to certain screens with an "IF" statement and PeoplePicker column from a SharePoint list

@caleb_abernathy
Are you sure the other users are using the most recent version of the app? Apps have been slower to publish these past few weeks.

Otherwise, I think the way you’ve written it only people in the 'ManagerPicker-Test' column in the table 'CTP - Processing' can see the label. But keep in mind my suggestion was to create a new table with a single column containing only Managers who should see the button instead.

—-
Please Accept as Solution if this post answered your question so others may find it more quickly. If you found this post helpful consider giving it a Thumbs Up.
Highlighted

Re: Restricting navigation to certain screens with an "IF" statement and PeoplePicker column from a SharePoint list

Thanks for the quick response.

That being said, within the 'ManagerPicker-Test' column, I am the only one in the entire column. (*See attached image*). 
So, with the logic presented above, I should be the only one that is able to see the labels given the code -- correct?

Highlighted

Re: Restricting navigation to certain screens with an "IF" statement and PeoplePicker column from a SharePoint list

I think it isn't working because we are using a Global Variable. So, whenever I sign in to test it, it remains true since I am a manager. 

Is there a way to change this to a local variable or make it adjust/reset each time a new user signs in?

Highlighted
Community Support
Community Support

Re: Restricting navigation to certain screens with an "IF" statement and PeoplePicker column from a SharePoint list

Hi  @caleb_abernathy ,

 

I made a test based on @mdevaney 's code, it works well for your case.

I put code '!IsBlank(LookUp('CTP - Processing','ManagerPicker-Test'.Email = User().Email))' to Visible of button directly, the button only be visible when I was in the SharePoint list person column, If I remove myself from the list and refresh the SP list connection, the button becomes invisible.

Snipaste_2020-04-02_13-57-30.pngSnipaste_2020-04-02_13-57-24.png

Could you please create a new canvas app to try again?

Sik

View solution in original post

Highlighted

Re: Restricting navigation to certain screens with an "IF" statement and PeoplePicker column from a SharePoint list

Hi,

Thanks for the quick reply.

As you can see by the *attached image* I used that code exactly the way you stated - on the OnVisible property and my label is still visible for some reason.

Yes, I did take my name out of the column and refresh the data source. 

Thanks for any insight.

Highlighted
Community Support
Community Support

Re: Restricting navigation to certain screens with an "IF" statement and PeoplePicker column from a SharePoint list

Hi @caleb_abernathy ,

 

That's odd. Let's try to avoid the impact of the delegation issue. please try this

1. ensure to take your name out of all row in sharepoint list

2. save User().Email into a variable to avoid delegation issue, Set App.OnStart: Set(MyEmail, User().Email), Click Run OnStart button to trigger it.

3. Then try this code to Label.Visible property:

!IsBlank(LookUp('CTP - Processing','ManagerPicker-Test'.Email = MyEmail))

Let me know the test result.

Sik

Helpful resources

Announcements
secondImage

Demo-Extravaganza 2020

Check out these cool Power Apps & vote on your favorite!

secondImage

Robotic Process Automation

Let's talk about the solution provided by Microsoft for Robotic Process Automation (RPA)

secondImage

Community Highlights

Check out whats happening in Power Apps

secondImage

Community User Group Member Badges

FIll out a quick form to claim your community user group member badge today!

Top Solution Authors
Top Kudoed Authors
Users online (5,839)