cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
MechEng2013
Advocate II
Advocate II

User() Function and Lookup to Users table

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!

1 ACCEPTED SOLUTION

Accepted Solutions
Pstork1
Dual Super User
Dual Super User

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 I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.

View solution in original post

6 REPLIES 6
Pstork1
Dual Super User
Dual Super User

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 I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.

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?

MechEng2013_1-1668618401018.png

 

MechEng2013_0-1668618375986.png

Here is on a text label outside of the OnStart Function:

MechEng2013_2-1668618557905.png

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.

image.png

Doing that on mine works fine.

image.png

 



-------------------------------------------------------------------------
If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.

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.



-------------------------------------------------------------------------
If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.

Thanks for the tips and explanation, very good info sir!

Helpful resources

Announcements
Power Apps News & Annoucements carousel

Power Apps News & Announcements

Keep up to date with current events and community announcements in the Power Apps community.

Power Apps Community Blog Carousel

Power Apps Community Blog

Check out the latest Community Blog from the community!

Top Solution Authors
Top Kudoed Authors
Users online (3,802)