How To Add Role Based UI To Your Power Apps | Admin Based Access

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey youtube welcome back to the channel today we're going to be making a pretty simple roll base access system in powerapps this is a feature that i think is a must know for anyone building business applications with powerapps a lot of the times you're going to run into scenarios where certain people in your organization are going to need different access than others so what we're going to be doing today is taking an example of a admin user and a non-admin user in the same power app but seeing things conditionally again you could really make this as complex as you need it to be for your organization so without further ado let's get into the video so i've just built a test canvas app here and the kind of goal of our app is we're going to have three screens we're going to have the home screen with buttons and then we're going to have two different screens that the buttons are going to navigate to so we're going to have a user screen and an admin screen so to start things off we're going to rename our first screen and just call it home screen now we're going to drop in another screen and this one we're going to rename to the user screen and we'll go ahead and add a icon to get back to the home screen so we'll just drop down one of these and over here on the right we can change it to a back button resize that a little bit and on on select we are going to delete the false here and type in back and open and close parenthesis and this is a function that will bring you to the previous screen and we'll throw down some text to show what screen we're on so we're just going to drop down a label and say welcome to the user screen so i've gone ahead and made that a little bigger and now we're going to do is come over here and click the three dots on our user screen and we're going to click duplicate and we're going to rename this to admin screen and we'll change the text here to say welcome to the admin screen so now we're going to head back to our home screen all right so we need some buttons laid down uh we'll bring a regular button on the screen and we'll say uh go to user screen and we'll copy and paste that and we'll say go to admin screen so again the concept we're looking to build into this app is that if you are flagged as the app when you load it up as a user is you're just going to have access to this button here to go to the user screen however if you're flagged as an admin you're going to have access to this admin button as well as the user screen again this is just kind of an intro to this functionality but you can certainly take this knowledge and build on this from here so moving on what we're going to do is go to sharepoint now and we're going to want to come to whatever sharepoint site is relevant to our project mine is just powerapps university and we'll click on that so from here we're going to come up to the left and click new and we'll do a new list so we're going to go ahead and call this list admin list and this is the list that we're going to put all of our users emails in that are going to be flagged in the app as admins uh you certainly could put users and admins in the same list especially if you are going to have let's say five or six different levels to your application but in this case we just have one to two so you're either an admin or a user so we'll just say admin list and we will click create so again now we're on our list this is how you're going to tell if a user is an admin so what we're going to use this title column for is just to put the email addresses of the admin and again when admin would log in with their microsoft account the app is going to check their email address see if it's in this list and then determine if they're an admin or not so i'm just going to go ahead and click new and i will paste my email in here so now my email is in the admin list we're going to hop back to the powerapp quick and wire this up so we're going to want to go to the data sources section and click on add data and where it wants you to select the data source we're going to type in sharepoint then make sure you click the bottom one the top one is dataverse and click a connection or add a new connection if you haven't yet and we're going to find our site and we'll click the admin list sharepoint list so before we go any further i'm going to add actions to these buttons so we're going to go ahead and click on this user button and delete false make sure we're under the on select property and we're going to say navigate and we want to say user screen so navigate again is the function that's going to take us to another screen and we'll do the same for the admin screen make sure we're on on select again we'll type in navigate and then admin screen admin screen and close that off so now these buttons if we go into the player will take us to the user screen and the admin screen alright so next we're going to click right above the home screen we're going to click app and this is going to be the different properties of the app you can access so we're not going to go over all of these today but what we are going to go over is the onstart property and if we click on that it's pretty much what it sounds like we're going to go ahead and expand that formula bar whatever powerfx code is in the onstart property so again under app this is going to run while the app is loading up so as the app's loading up we're going to make it reach out to sharepoint to see if our email address is in that list of admins if it is we're going to set the admin variable to true if it isn't we're going to set it to false and from there we can put logic in our app to show us the different buttons based on that so we're going to start with a if statement so if and then open parentheses and then we're going to put is blank again these blank function is going to check whatever you feed it if it has no value it's going to return true but in our case we do want to know if it's there so we're going to put a exclamation point in front of his blank and that's going to give us the opposite of his blank so it's going to say something is there and now we have to tell it what we want to look for so we're going to use the lookup function and open parentheses on that and first lookup is going to want a source so we're going to type in admin underscore list which is our sharepoint list and then we're going to say comma now it's going to want to condition so if you remember we put the title to our email address so we're going to say if the title equals and we're going to say user open close parentheses and then dot to get the properties of our user account and we're going to click on email down here or we could type in email so we're going to do one closed parentheses to close off the lookup and another to close off the is blank and then we can do a comma to write to the true value so now we're going to type in the word set to set a variable and we don't have one yet so we'll give a new one so we're going to put the word is underscore admin then we're going to say comma true and we're going to close off that parentheses and we'll do another comma for the else value as you can see right there and we'll say set is admin and we'll do a comma to set the value and we'll say false and then close that off and then one more close parenthesis to close off the if statement and we can come down here to left and click format text so again to recap what we just did when the app starts so using the onstar property we're going to check if a record is in the admin list where the title so the title column matches the user's email who's signing in we're going to set the admin variable to true if it isn't we're going to set it false so now we're going to go down to our admin button and click on that and up here on the left hand side and the properties we're going to click on visible and we're going to delete the true and just type in the word is admin so we can see right now that that is our variable it is blank because it hasn't been set true or false yet so even though that our email address is in the sharepoint list the onstart hasn't had a chance to run yet so what we're going to do is to file and save and we're going to publish and reopen this app so now when we load back in the button that just went away should be back since we're going to run that on start code and it's going to flag us as an admin we're loading up our app right now and we can see that the go to admin screen button shows up and we can navigate to the admin screen and we can go to the user screen since we're flagged as an admin what we're going to do is close out of the app and we're going to go back to our sharepoint list and we can delete my email so if we're removing my admin access so to speak from this app and then we click back on conditional access app we're gonna see that we no longer have the admin access and we no longer can see the admin button so this has just been a brief intro into conditional access with powerapps using a sharepoint list i hope you got something out of the video this is obviously again like i mentioned before something that you can make really intricate into your applications but this is kind of the concept with that i hope you enjoyed the video please reach out with any questions or comments below make sure to like and subscribe and we'll see you in the next video
Info
Channel: Power Apps University
Views: 35,410
Rating: undefined out of 5
Keywords:
Id: n2bP2ZknetU
Channel Id: undefined
Length: 7min 52sec (472 seconds)
Published: Wed Jun 29 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.