Hello Powerapps community!
So, to make this concise and not too much background info... I need to access the Users Record of the current user (from the Users table). With 'User()', I can access current user's email, which in my mind should be able to be used for the lookup to the Users table in order for me to access all the data in that record.
The problem I'm having is that when I place User() inside of a Lookup or Set function (in the App.OnStart and in Homepage.OnVisible), it returns nothing, or gives an error. I tested it out in a Text Label directly and it works fine there.
1. Am I on the right track as far as lookup up to the Users table?
2. Any thoughts on why User() is acting this way inside a function?
3. I'm connected with Office365Users, is there something here that makes what I'm wanting to do easier? I'm not familiar with this at all.
Thanks!
Solved! Go to Solution.
If you mean the Dataverse users table then the following works for me.
In App.OnStart. (Remember when working in the designer you have to run App.OnStart manually
Set(currentUser, User())
Set Form Data Source for Users table and Item to
LookUp(Users, 'Primary Email'=currentUser.Email)
If you mean the Dataverse users table then the following works for me.
In App.OnStart. (Remember when working in the designer you have to run App.OnStart manually
Set(currentUser, User())
Set Form Data Source for Users table and Item to
LookUp(Users, 'Primary Email'=currentUser.Email)
Thank you for affirming my logic.
I'm finding that while in the test mode of the function below, the record returns blank. But the code does actually work. This must be some glitch from Microsoft?
Here is on a text label outside of the OnStart Function:
And this does output properly.
As long as this code pulls all the necessary columns I need from Dataverse, then I should be good to go!
Thank you
Did you use the context menu on the app to manually run the App.Start? As I mentioned when in the designer app.start doesn't run on its own.
Doing that on mine works fine.
Yes I was running manually and still got the error inside the preview test window. But when I run it, it does work. Strange.
Now I also did find that I do have to make two lines... this is what works for me:
Set(varCurrentUser, User());
Set(varUser, LookUp(Users, 'Primary Email' = varCurrentUser.Email || 'Full Name' = varCurrentUser.FullName));
If I do this in one line, it doesn't work:
Set(varUser, LookUp(Users, 'Primary Email' = User().Email || 'Full Name' = User().FullName));
1) You don't need the || in there. If the Email doesn't match then its not the right user even if the Fullname does match.
2) You shouldn't try to do the Lookup in the App.OnStart because the connections may not be fully working yet. The lookup should be in the Submit button or somewhere else after the app finishes loading.
3) Using the User() function inside the Lookup directly won't always work because that form isn't delegable so it may not find the user. Storing it in a variable first is delegable.
Thanks for the tips and explanation, very good info sir!