PowerApps Hide Button Based on User and other fun

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
in today's show we're going to talk about power apps hide a button based online user and other fun tricks you can use right you always have these buttons you want to put on the screen you want to security trim them somehow but ruin you know what is the best way so we're gonna do is we'll talk about some basic ways we're going to talk about some more advanced ways and then I'm going to set the stage for some future videos to talk about really really advanced ways but the idea is I want to make sure you understand this core concept because it's gonna help you build better apps but first here's our intro hi my name is Shane young with power apps nine one one those guys in today's show it's all about showing and hiding buttons and power apps so this is one of things that you know if you've done it a bunch right yeah this is super easy I get it but for a lot of people it's a real challenge and for some people they end up building 2nd and 3rd apps just because they don't understand the key concepts around showing and hiding things based on things like who's logged in looking at a security group looking at a list of data looking at statuses that type of thing so that's what I want to do in this video just kind of walk you through all those different concepts make sure you understand fundamentally the really simple concept and then show you some different ways we've expanded upon it so it sounded like a lot of fun me too so let's just switch over to my desktop and take a look over here my desktop you can see I've just made a quick little app and these are really this is different scenarios we're going to talk about so we're gonna look at like hard coding some info we're gonna look at you know hard coding the user the date we're gonna get security by securing a data source so we're gonna do is we're having a data source that has a list of users that are allowed to see the button and then talk about how we use the lookup function to do that and then there's last two there those are just kind of setting us as we move forward into other more advanced concepts but for most people this middle button right here this is the button you're looking for that's the one that most people are after so we'll get to that one so let's just kind of get out of here and so the first thing I want to just make really clear so let's talk about the super simple first right we gotta crawl before we walk some other cliche thing someone throw a button on the screen and so for this button the most important thing to understand is that the visible property is what determines whether or not this button shows up right so he'd hit the drop-down up here and so visible is just simply either true or false that's really important to understand right no we have true and if we type in false no you got to type in false in a way that is spelled correctly false right then the button just doesn't show up so that's all this particular property cares about why I say this is because all that matters is whatever you put here equates to true or false so what you might do you might say 2+2 does that equal or evaluate to 4 it does right 2 plus 2 equals 4 is true so this button shows up you change this to 5 the button goes away it's that simple of a concept right and if you understand that right duh that's good because all we're gonna do is take and reinforce and build on this for all of those buttons down there that's all they are is a version of 2 plus 2 equals 5 we need to get something that equates to something and that you need to evaluate to true or false notice there's no ifs right we're not gonna have to do any if type of thing in here because all we ever need is true or false so the most common thing that I will see from people is they want to show or hide a button to one person or to two people so what a lot of times you'll see is some guys if user dot email equals and then it's Shane at power apps apps nine-one-one com and so now the system's checking that evaluates to true so it shows me the button if I shared this app with Chuy when he logged in he would not see that particular button because Chuy's email address does not equate to Shane at power apps nine-one-one now remember power Apps is case sensitive so if we want to appear and we capitalize Shane properly shift s the button is going to disappear why because in our active directory for who knows what reason my email address is capitalized exactly like this so if you're struggling with that type of scenario one of the things I will do and we're gonna do a lot of this right the label on the screen and just be like hey what does user dot email look like and so this is going to show me oh look it is capitalized right it would play the hole easier see but it's capitalized the lowercase s capital P capital a so that's how I knew what it was so that's one way to go after it right and if you're storing like whatever system you're using to feed the data in you're storing the email address using this property then you know they'll always match but what you could do is maybe you know you're having problems with this because everyone in your environment is different you just you're you're sick and tired of dealing with it so remember you could use something like the lower function and say all right lower right which turns that string into lowercase and then lower on this one and so then now the two should match because right even if I go on here and type in chained in all caps what's happening with the lower function right easy to test over here just baby I put lower on this like this and this what happens it is going to spit that out in the whole thing in lowercase so that's one way you know you can convert to lower or upper if you need to so easy enough little thing but but this is the first way that we often will security trim things especially like one in the testing or prototyping phase and I don't want to mess with proper security I just want to literally show the button to myself or show the button myself and my client so there's the two of our email addresses are listed boom like well how would I list two that's a fair question remember all this has to do is return true for the button to show up so what you do is you can do an or and you could say or and we're to skip the whole lower thing for now but user dot email equals chewy at power apps oh my goodness typing is hard people.com like that and so then if the user equals either the left or the right right because in an or scenario if either this side the left side or the right side of the or statement is true the equation returns true if both are false then it would return false now so that would be a way to show it if either one of us logged in so I have customers where we just need to hide this thing for two or three people we do something like that another thing that I want to point out real quick this is bonus learning this user email oh quit putting this in your apps all over the place right I go on an app sometimes it have this function 400 times that is 400 times the system has to go and check what you are what I do and all of my apps appear under app you can see so on start when the app started set VAR user email to be user dot email so this variable gets created as soon as the app loads so then down here and all of these places where I was using users out email before I'm now just using VAR user email and so then right here it would be VAR user email all right everything works exactly the same as before but now instead of making a call all the time to Active Directory to get the same email address back and forth which is really inefficient than your Akshay my apps are never slow and it's not it's not an efficient on my happy desktop you're on a fast connection but what about the man or woman out in the field with a you know a cell phone on a 3G connection right that extra call might take them two seconds so you want to build your apps as efficiently as possible not using the user function over and over again that's a pro tip all right there's me all pro tip I'm fancy no I'm not um sorry anyway okay so that's the basis of it so that's the first thing that we do so if we look at my super-secret admin button that's literally all I did I said bar user email equal Shane at power FS nine-one-one that was true we showed the button you can also have buttons that show up based on things like a date right because this has to be true or false so I need to say hey it's today seven twenty seven twenty nineteen it is then boom show the thing you know so you can have this maybe have a button that says you know get my birthday surprise and it's based off of the user's profile birthday or you want to have a button that only shows up on Christmas Day yeah hey congratulations for being the office in Christmas Day you know you have those type of controls because we don't care this just needs to equal true or false okay horse dead horse beat got it okay so let's move to the more complicated one this is the one that you're really after so instead of going here and having a whole bunch of words right you're like I don't want you and modify the app all the time I want to make it so the users can just throw some data out there and then we're gonna security term based on that I'm with you so what I did is to make this easy on myself I wouldn't made myself a SharePoint list I called it access control and literally all I'm doing is I'm storing in the title column the users email address so Shana power-ups 9 1 chewy at power apps 9 1 1 so both of these are in here so the idea is that my user who has rights to edit this list could come in here in delete chewy to take away his access or add nicola to bring in her access right it gives them the ability to come in here and manage this list where they want to to do this and this is showing you sharepoint right but in reality I've done this with as your sequel I've done this was the CES right the common data service I've done this from other different data stores so it doesn't have to be SharePoint sharepoint just visualizes Joey well for these videos but now that I have the users that I want to see them in the button now that I have the users that I want to see the button in here what we're going to do this is the magic right is what I want you to do you know what that's too hard let's just go over here let's just break it down so we're going to use a label so what I'm gonna do is the first thing I wanna do is I'm gonna go look up for that user so I'm saying look up from the list I call it access control where title because that was the column I used equals var user email all right and then it's it's complaining if you hovered it was Sam I've got a record I'm expecting text I get you so then we're just going to do dot we can either do the dot ID or I would probably most typically do the dot title so I can see what's returning so we're going to put that on the screen so you can see that that clearly returns a record right so that returned the value title which is what we went search for so that tells me that my user is in that particular what do you call that my user is in that list of data ok right because we turn the value so what I end up doing here is I'm going to take this I'm gonna right so if that comes back what I'm gonna do is I want to check to see if is that blank okay and so in our case what happens is it blank no right that's false so if it is not blank that means the users in the list means I should show them the button well false says don't shows in the button so then we're going to do is when we go out in front of that and we're going to use the exclamation point which is the not operator so the opposite of false is true so then that is how we determine to show the button okay let's talk about that again so we went and looked up against our SharePoint list to see where the title equals of users email okay and we returned the title property we just need to return a value so I returned the value of title I then check to see is the title blank so if the users in the list the title is not blank so this would be false and then the opposite of false is true so just to help you I'm gonna go over here let's say that I get thrown out right I am not allowed to see that button anymore so we're going to delete this delete so then the next time I'm logged in the app so I'm going to speed that up and it's gonna save you data source and refresh the data source all right after I fell asleep waiting on to load it is and so then now we're going to employees or no not employees access control we're gonna refresh that list and what you should see look at that the button went away and this value is now false and right let's just baby step it again so if we do a lookup for the user where the title equals Shane at power EPS 9 1 1 nothing gets returned it's a blank return that means the user is not in the list so that's the check that we're doing so that's blank so then I would go over here and say is blank [Music] right which will then give us a true because it is blank and we know that we don't want to show it to if it's the point if it is blank so we're just gonna do the opposite so home put an exclamation point and just like that the button is now hidden because I'm not in the list but if chewie logged in then whoo what would happen he would see the button so this is how you can make a dining security lists and so in this case I'm letting my users maintain this over here and SharePoint on their themselves right so I'm giving the the manager or the you know whoever it may be the ability to edit this list and everyone else can just read the list because we I need we have a query for it but so that person can do it if I was using CD s or or sequel right I would just make an admin only screen where you could log in and add users or remove users and so that would take care of writing it back and forth the datasource but the key concept I want you guys to see is this idea that we go look up to see if the user is there and then we do the ops of that which is blank all right or which is not so then we and that's how we get to this I mean that's the reason that this button right here is no longer showing up because I'm not in the list okay that was the big thing I want to show you let's jump over here to screen for we'll come back to these two buttons in a minute but so let's talk about applying this a little bit differently as well because another scenario that comes up in a lot of the apps I personally build you know this ability to hide or show buttons nine times out of 10 it's honestly this it's you know VAR user email equals this person or this person and it's not going to change very often so we just we just hard code it in the app we call it a day I'm being honest my name is the best but don't see what happens a lot you know it's this or chewy and that's how we go this doing it by a list that only happens in my really big customers who have very large departments and also they want a security trim it for 10 or 20 things or you know what let's before we get into that let's make this a little harder you won't make this harder instead before your next screen I think you do so in this scenario we went and looked up a user based on this but what if you want to check the users access right so we can come over here and even add a column right so maybe add another text column called you know access and so we'll save that and then we'll do a quick edit here and so we're going to say access is none for chewy and then we're going to put me back in so Shane power-ups right I gotta get it capitalized right or I gotta escape out of that and then we're gonna say full exit quick mode so we have done this for customers who just popped my head so so now we've got multiple pieces of information in here so then now you can apply that same concept you could say look up access control title equals VAR user email and oh we got a refresh your data source and view data sources access control refresh and well that's refreshing let's go over here I named that access service oh and I put one L on full who I would have confused me a lot if I hadn't caught that lucky lucky day there we go well exit the quick edit mode shew of course now or we'll have to refresh again to get the right data in okay area so then now what we're gonna do the buttons back yay so back here with say and chewy calm down buddy and access equals fool just like that so then you can see I still have ability to see it but so then now this gives you the ability to query on multiple columns so like one of my customers apps there is basically we have three we have one list and we have three statuses right you can have no access you have administrator access or you have viewer access and so the different buttons in the app we're all query in that same table but they're just taking advantage of multiple attributes right because we can do a lookup function against two columns at once right so that's how we're checking to make sure that not always this person in there but they also have access as full and so if we were to change my access you know just to make sure we see how this works all right so we change my access to reader ah doesn't matter we'll say save and so if we go back over here and refresh this data source one more time just like this right now this button is set to false for this label right because what we've been using to show whether or not we'd see the button because title equals VAR user email check and access equals full full in an scenario if the left is true and the right is false then what happens it is false because in order for it to be true both sides have to equate to true so understanding your logics of ands and ORS and is blank and you're not operators right all little pieces of this puzzle but the more that you understand them more efficient you can write these queries ok ok let's go to screen for real quick so we're just do this go to screen for so then over here real quick what I did is I built my gallery but what we're doing is we're showing buttons based on the status so what I'm asking here is one of the properties in that SharePoint list is are you good at your job and it's a true or false property and so you can see that if the property is true then we have the button to give them a promotion but if they're bad at their job so good at their job as false then we have the button to fire them so sorry Greg but you're you're probably getting the can but now so the idea here is you know I have I was working on an HR app suppose to be working on it right now actually instead of making this video Shh don't tell my customer but in their app you know basically the performance review has different statuses there's the draft status when the manager and the employee are working together then there's the approved status and then there's the HR approved but basically when you go into the gallery we're showing you a different button in the gallery for each person right these are all the people that are reported to me in their app and so then we're showing a different button based on the different status and so right it's probably as easy as you hoped but give promotions so good at their job since it's a true or false field this returns true or false so that's what's showing up here to fire them button though this is a little more interesting this is another thing I want to talk to you about so the fire them button what happens on this one is instead of redoing the equation so checking to see if they were good at their job again or any type of thing I know that at any point that I either want to show the gift promotion or fire them button right it's one or the other so I'm doing the evaluation on the give promotion and then I'm setting the other button the fire them button to be the visible property right because the visible property returns to true or false and so then the non operator of that so it'll always be the opposite right that's the reason you don't ever see two buttons here because it can't look good I'm just saying all right button eight right you're visible property was good at their job which is true or false and so then fire them your visible property is just the opposite of the give promotion button so another one of those tricks that I use to cut down on the amount of logic I have to write but it also really cuts down on you know any confusion right because I can see a scenario where all the sudden the equations are changing and things like that and all of a sudden I'm showing people both the promote them and fire them but and I'll get an idiot I know I should I ever show one or the other so I do that you want to get real fancy sometimes what I'll even do is I'll stack the two on top of each other like this so then now it looks like that one button is actually changing in reality it's two different buttons if you want to get fancy again you could make the button change that's too much work I'll be honest I never do it I put two buttons on there and I just show the appropriate one so I wanted to show you guys that but I think this comes up a lot for me as well as in my galleries having dynamic buttons alright so back over here real quick the last two we're not going to get into too much but I wanted to set the stage because I think I owe you more videos on these so this one I am using I am showing based on the office 365 Pro Profile property so I'm going and getting the user profile of the logged in user right bar user email I'm getting their department property and then if their department equals services I'm showing the button if Department doesn't equal services they don't see it so that way only the does services people see this button or only the HR people only the people that are in the executive department but it's a way to use your office 365 user properties to do this so that's pretty cool this one over here this one's really complicated this is why we're not getting into it but this one I'm using the office 365 groups and I'm saying hey list the group members and so what's really hard is getting this group ID I mean I know how to do it I'm going to show you how but it was such a painted but I wouldn't take another 20 minutes so it's gonna get its own video but once you have the by the hear what I'm saying is go look and see is the VAR user email the logged in person is their email listed in the list of mailing or mail addresses for that group if it is show them the button if it's not don't and then we also have the same concept already done for azure ad security groups but once again that's probably its own video as well but it's probably take me 20 minutes to show you how to deconstruct your as your ad to figure that out but a lot of future stuff kind of come in that should be pretty cool so okay hopefully that helps you alright this is a video that people asked about all the time so I want to get this out here you know if you got any questions or comments hit me up below hit me up our apps nine-one-one you guys know the drill right you can email me shane at power apps 9-1-1 on twitter at chains counts all those fun places but this is just another one little things put your toolbox make you better at power apps in will build cool things together alright well it's Saturday so I'm gonna go out and play outside we're showing hot I'm gonna chase chewy but thanks and have a great day hey it's me again if you got a second click the subscribe button that always keeps me making more videos or if you want to work together need some help getting your power apps going hit me up with power apps nine-one-one always happy to work together or finally if you're always looking for more videos that's probably what it is check out the power apps playlist over here and you know enjoy that alright thanks and have a great day
Info
Channel: Shane Young
Views: 59,723
Rating: 4.9537191 out of 5
Keywords: PowerApps Hide Button Based on User, PowerApps, Shane Young, Shane Young PowerApps, PowerApps911, Power Apps, PowerApps Show and Hide buttons, powerapps user lookup, powerapps show button if user, powerapps hide button, powerapps gallery hide button, powerapps lookup user, office 365 groups powerapps, powerapps user profile v2, powerapps tutorial, learn powerapps, powerapps tutorial for beginners, office 365, powerapps sharepoint
Id: 0MB-z9cyFCQ
Channel Id: undefined
Length: 23min 43sec (1423 seconds)
Published: Sat Jul 27 2019
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.