PowerApps Filter Gallery by the Current User

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
in today's show we're going to about power apps filtering a gallery based on the user so the idea is you want to have a gallery of information you want to store all your data in one list but you want your gallery just to show the logged in user the information that they should see so that's what we're going to do we're going to talk about how to do that in a very simple way we're going to talk about how to do that in a little bit more of a robust way well harder for you but better in the long run and then just tell us about other little pieces along the way should be a pretty quick topic but I just thought since I've got this question so much recently we should make a quick video but first here's our intro hi my name is Shane young with power apps 9 1 1 those guys in today's show we're going to talk about power apps filtering gallery based on the user and this request I keep getting it I've got it I just got an hour ago that's what made me say alright it's gonna make the video so that's why I'm down here instead of you know enjoying a happy Friday choose you or they're napping kind of jealous of that but whatever but so what I want to do in this video was just talking about different ways that you can store the user value and then how you can take advantage of that to filter the gallery if you know this stuff we've covered in other videos kind of like in little peace famille actions but I thought this was a standalone enough concept that we just go through it in the end talk about some of the ups and the downs some of different things I've seen also we're going to use a SharePoint list for still more examples here but once again this is not exactly tied to SharePoint in any way so you can do any of this whether using sequel or c.d.s or any other data source and some of those other ones like CES might even introduce some additional options but we're not gonna get that far down the rabbit hole Oh self-control so anyway good fun video good refresher for some of you that's okay so if we switch over here to my desktop here is an app that I built called not a fancy customer node app and the idea I guess we'll just hit place we can run it real quick is in my app you know you have these different pieces you look at and then come in here I can edit a record and more specifically I can create a new one right and let's see we'll call this one Luke's video games and I see play all day for free who's a very giving child wants my money so so there you go alright so just a simple little app now what happens a lot of time says you have this one app and you're you want to capture these notes but you'd really rather this instead of showing me all of the users notes you want me to come in as a normal note in ER and only be able to see the notes that I've put it in the past very very common requests and so the way that we can do that is over here on the gallery that we've added right the items property we can filter this data and so the first idea you might have would be to say all right I'm gonna just do a filter customer notes and there's a separate video I'll link down the below where I covered filter in greater detail but we're not getting the nuance as a filter today but I would say filter customer notes and what you probably say well we know in SharePoint alright because we're using a SharePoint list there is a column called created by and there is a display name right or an email Oh interesting so I could say created by email equals and so then you could do a function like this the user function which ants there's a separate video on that I'll link to that too I'll be linking a lot apparently but you can do user dot email and so if we close this out and we cross through well fingers we might see some stuff we might not and so one of the couple things that's happening here so one is you can see that we're getting a delegation warning so that means that this isn't being processed by our datasource this is actually being processed locally so that means if your list has more than 500 items by default you're going to have problems where it's not going to get all the items in your list and more specifically you can't update that list that limit to 2000 but to thousands the hard limits you can't go any further than that so this isn't going to be a good idea for that you can also see that even though I clearly created this I'm not seeing it and I'm not really sure why so here's what I would do to troubleshoot this let's get rid of this filter so I'm just going to use control Z so put it back to where we started no no I fine we just won't use cut we'll just do it this way so that puts all of them here so that would go down here say all right so instead of show me this item note I'd say show me this item dot created by and and dot email so Shane and power-ups nine one one all right look I created all them shocker so that my insert a label it's going to not inside there they'll get rid of that will just go right over here insert a label and so then we're gonna do here is gonna say well that user function what do you see and so then this is going to show me so this is a very common problem right so we were trying to do a comparison we said where this equals this remember power apps is case sensitive so even though the email addresses are the same they both say right what kind of drag it up you're seeing what do we see it they both say Shane at power ops nine one one one is got capital Shane and the other one has got lowercase Shane so that's why the match wasn't happening in this scenario so what we could do I guess we can come over here we say all right so we know that comes in like that so one option would be to go back up here and say okay let's put a filter back in here so filter customer notes where created by dot email equals user dot email mmm so we know this doesn't I mean we know this would technically work but it's not match because they don't match so you might use a function like lower and say hey just take that convert it to lower and then take that and convert it to lower and so then now both sides of the equation should have all lowercase Shane at power wraps nine one one for the matching portion and so that's why you see the data now once again though remember blue squigglies yellow warnings means delegation is happening to you so your SharePoint list is not or your queries not being processed in the SharePoint site it's being processed on the power app side which means you only get the first 500 or up to two thousand records depending on what you have over here in this app setting advanced so by default it's the first 500 so if your list has a million items only the first 500 are getting queried probably not going to work very well and also this is showing you a SharePoint scenario but this could happen to you in sequel as well if you were trying to match and you're using this or because this lower function can't be delegated so anytime you see this watch out for your limits that's okay because we don't really want to do it this way but I wanted to show you why you shouldn't do it this way hey so if this was a requirement you gave to me I almost put this back to just regular customer note so we don't confuse ourselves here's what I would want you to do I'm gonna go over to a share point I'm gonna add a column so I get this click over here and we'll save you data sources and it's gonna show you all the data sources which is going to be my fancy customer notes if it ever finishes loading okay so there came head took it a second I who knows so one of the tricks you can do hit this button right here and say edit data this is super handy because this is gonna take me straight to my SharePoint list yay so now I'm gonna come over here I'm gonna add a column I never like to use this out of column here because I feel like it can do what it wants to do so I do over here the old-school way someone say list settings we're going to say create a column we're gonna name this creator email now notice I did not put a space in here notice Chuy is over there having problems but so notice I did not put a space in here because when you create it whatever you use is the name when you create it's gonna do it the field name is what we have to reference some power apps we don't want to mess with spaces so call it crater email and then we're gonna do single line text and we're gonna say okay boom now we have creator email so then what I'm gonna do because you don't like that I'm gonna click on it and we go back in here and now I can put the space in and then say okay and so this just gets rid of that problem SharePoint right if we hover look down look right down here when I hover over create or email notice that the field name is still creator email even though we put the space there but now we don't have a lot x20 stuff so very helpful okay so now I have a creator email column and it is a single line of text let's go back over here if you're doing this in sequel right we would have just made a text or a bar car column over in sequel right so this isn't just SharePoint for a car column over a sequel same results okay so now we have that column so I'm gonna go over here to my forum where I do data entry and we're going to edit fields we're going to add a field because we need to update that column right and so there is a column now Oh nope it is not here why is it not here because we need to refresh our data source so we hit X we're going to go here to view data sources again and then we're gonna click refresh here right because that's who fetched the new column so it got all the new data which wasn't new data but got the new schema which was our new column saying for sequel so there you go so then now over here we can click Edit fields we can add a field and there is crater email woohoo we're going to say add and so right now it's blank so let's quick hold down the Alt key and press edit so we can see now I don't want users typing in their own emails because users are untrustworthy all right we can't trust in and do anything so what I'm going to do is I am going to change this a little bit and I'm going to say all right we're gonna unlock the card and so instead of developing parent default we're gonna say your default should be user dot email so that would be the logged in users email address right there I am Shane at power apps 9 1 1 and so then what we can do is we're just going to say alright in this field instead of the display mode being tied to the parents display mode we're just gonna say hey your display mode it's always going to be view so that way they can't edit what goes here in the Creator email you could also get more complicated so right now if we look at the default it is always set to user email and what you might do though is you might realize say you know what stead of making it always that kind doesn't really make sense we'd say if form 1 right it's never form form 1 dot mode equals new or so it would be for mode new sorry for mode dot new so if the form mode is new then I want to make it user dot email and if it's not that then I want it to be parent default that's the more correct formula because you don't want to modify this every time you want it to follow along so if the form mode is in a new mode then it'll be the user email if not it's imperative alt so that way you're always you're not messing data okay all right and so then now we should go to see that let's just cancel out of here so right now crater emails blank but if we do a new one right so this is new customer they are the best boom and we're I'm gonna fix my typos we hit save and so then now the crater email for this one alright if we click on it is Shane at power apps nine one but all these other ones still show blank and if we change them they're not going to get messed up either because we wrote that little function okay so now we have a way to store the actual email address of the crater from behind the scenes so then now we can go back over here and so we're going to change this from gonna say filter customer nodes where create or email there it is equals user dot email like that oh it looks how you throw mad at me so this should work they let's make sure it works okay and so what it's saying is hey I can't delegate I can't send this function over to SharePoint so I gotta do it all myself so this comes up so I'm gonna do is I'm gonna grab this my say control X I'm gonna go over here to the app I'm gonna say on start I'm going to say set of our user email that's not how I do it I just I devour user to be user like this this isn't almost every app I write so the idea now is that any time the app loads we de store the users value in the variable because that way I don't have to use that function 8 million times which sometimes you guys get in habit of doing so now over here we can say for the gallery we want to filter this for create our email equals VAR user dot email so should be the same end result boom but we don't get any of those little pesky yellow warning triangles because we are now referencing a variable which is fine instead of referencing a function which calls delegation and that would've been the same where there had been SharePoint or sequel or just about any data source so this is the the more correct way to put that in place but now we've got just we wanted instead of seeing all of the users here only seen or sorry all the customer notes we're only seeing the customer notes that me the logged in user set so that is in a nutshell how I would do this for you or at least introduce you to the topic now you noticed over here that we were showing the crater email that's pretty confusing quite frankly so what I would probably honestly do is come back over here and click on this card and so now that I know it works and does everything because I can see and I saw it was functioning the way I wanted I would just change the visible or off and now no one even sees it right but if we do a new entry and so we're just call this new two more and once we hit save right this is gonna show up over here even though you couldn't see it get referenced so and then if I logged in as chewy and came to this same exact app what would happen chewy would not see anything because chewy hasn't created any record yet should we should we do that just to show you prove that works probably so and one second let me switch over grab a chewy window back okay we got logged in as chewy right and you always tell because he has the purple browser and his cute little doggy pictures up here so we're gonna switch back over here real quick because what do we got to do we got to save this app and share it with him duh so save publish publish this version and then share this app and then we'll chewy the dog yep that looks good so share alright that is done we'll go back over here we'll say like this and it said we refresh hopefully - we can see the app just that fast okay so now after a few seconds there - we got the email I clicked on the link and so now choo he's gonna open the app and so here right Chuy's in he sees nothing and so then now he can say all right I want to create a new record and so what is the customer named chewy did this not time enjoy no I have said his name too much as I say save and so chewy sees it and if we switch back over to my version right I do not see it right we even refresh the data just to make sure and so there you go right so chewy and I both looking at the same app the same controls but we see different data because the gallery is filtered by the user okay so that was the first thing I want to cover the second I want to cover is some of you who will probably point out that the way that I did this so let's go back over here let's go back to our forum I'm gonna take our crater email and we'll make it visible again so we can mess with it so right now I'm doing everything as user dot email oh you know what I should have changed this to B bar user dot email okay yeah doesn't matter but that would be the more efficient way to write my code all right it's well faster anyway so so you point out well what if the email changes now all this is going to break I want to store the users ID that's fair but with the user function that we have access to or the user function we used so far we don't have access the ID so if you want to do what with the ID then what you're going to need to do is you're going to interview data sources add another data source we're going to type office 365 users and so then right here we've got the users control and so what we can do here we're just the label on the screen real quick to show us what we see throw it down here but so then now you can do office 365 users and then you do my profile like this and then you're going to do a little bit down here and so there's the ID and so then this should return my users a grid there it is alright so then that's not tied to my email address or my username or anything like that right so it's an ID that is unique to my account so then if that was the way you want to go what I'd probably do copy this I'd go back up here to app on start I'd be like all right how about this we'll just say set bar user ID there you go and then we'll right-click on this and say run on start and so then now here instead of if this set it to of our user email it would just be var bar user ID and so then if not it would be parent new very cool so then if we do play if we do a new record there you go you can see that being in there and this is the reason you want to make the form the card visible while you're testing and building because you see that it's showing what you want right so try with ID IDE are fun there you go and so then we say save will delete this label off the bottom because that's weird and so then now we'd say filter customer notes we're creator email equals VAR user ID and so then just like that we should see there's that and then that's still showing it created by email but you could just do this so this item dot Creator email which is no longer an email address so it's price Tilly name you give the column but it's doing it so this is the same thing the same results all right would work just the same in power or in sequel as it would in SharePoint or any other source but the idea now is that we're tracking the ID the reason I don't do a lot of this is because really email addresses and things don't change much and now if you want to show this person's name you don't have or their email address or you want to send them something you don't have that so what you have to do here back insert another label and so then this would be this item when I would be office 365 users and then it would be a search user or now it would be user profile where's user profile it's down or in a spell Shane user profile v2 what is their ID that would be this item dot crater email because of the weird naming that we did here and then now you could then do dot this boy name and so you'd get their name back right so the problem with this is if you've got a hundred or a thousand items in the directory right or in the gallery then it had to go run this function this lookup a thousand times once for every item in the gallery to go get this back right because now the data doesn't exist all you had in the record right because power apps want to show you this record you have the record you have this ID if you want to translate this ID then you have to go do a lookup and find the email address or find the name and I can make your app a lot slower so then you have to start looking for creative ways around it maybe if it's true this scenario we could just store the users display name in a separate variable right there's ways around it there ways to optimize it which is too deep for this video that was rabbit holes I promised I wouldn't go down but you need to think about that this times a hundred if there was a hundred records here it's not very efficient code and so it might be fine and my super PC here but might melt a cellphone if you're trying to use it on phone there so just things to think about oh I just remembered one last thing while it's almost ready hit produce on the video um so another thing to keep in mind that with this method especially in a SharePoint scenario is remember that while we're filtering the data in your power app they have access to that SharePoint list they can go around your app to go see the data so don't try and use this method to secure you know actual confidential information what I really recommend is I just put on a video a little bit ago I'll link to it below so many videos linked to but in that video I talked about environment and the security ramifications and how to get around them if you haven't watched that one or if this idea the user can cheat your app doesn't make a lot of sense go watch that video okay all right back to what I was just doing but but I think that's enough I think that gets you guys kind of wrapping your heads hopefully or you watch this video and leave me comments below and say hey silly you forgot to show us this or that but this is how I solve this problem because it comes up again and again with my customers right we want to be able to filter the data it only show people their requests or the things that they entered or things that have been assigned to them and so this is what we end up using is none of the special columns we end up storing a unique identifier whether that be the email address or the the actual ID which we showed both in this video and then we filter the data based on that so hopefully this helps you out any questions leave me notes below but if not thanks and have a great day hey it's me again if you gotta said I can 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: 65,312
Rating: 4.9694657 out of 5
Keywords: PowerApps Filter Gallery by User, powerapps filter, powerapps filter gallery based on user, powerapps filter sharepoint list, powerapps gallery, powerapps gallery filter, powerapps gallery items, powerapps filter gallery by current user, shane young, microsoft powerapps, powerapps tutorial, shane young powerapps, learn powerapps, power apps, powerapps in office 365, powerapps911, powerapps tutorial for beginners
Id: -VaADTTPYmg
Channel Id: undefined
Length: 22min 15sec (1335 seconds)
Published: Fri Jul 05 2019
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.