web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / User() Function and Lo...
Power Apps
Unanswered

User() Function and Lookup to Users table

(1) ShareShare
ReportReport
Posted on by 257

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!

Categories:
I have the same question (0)
  • Verified answer
    Pstork1 Profile Picture
    68,697 Most Valuable Professional on at

    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)
  • MechEng2013 Profile Picture
    257 on at

    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 

     

     

  • Pstork1 Profile Picture
    68,697 Most Valuable Professional on at

    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

     

  • MechEng2013 Profile Picture
    257 on at

    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));

  • Pstork1 Profile Picture
    68,697 Most Valuable Professional on at

    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.

  • MechEng2013 Profile Picture
    257 on at

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

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 793 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 333 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard