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

Community site session details

Session Id : KdtjtluIMD+o6QOYSSJ+aV
Power Apps - Building Power Apps
Answered

User() Function and Lookup to Users table

Like (1) ShareShare
ReportReport
Posted on 16 Nov 2022 16:11:08 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!

I have the same question (0)
  • Verified answer
    Pstork1 Profile Picture
    68,271 Most Valuable Professional on 16 Nov 2022 at 16:20:16
    Re: User() Function and Lookup to Users table

    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 16 Nov 2022 at 17:10:22
    Re: User() Function and Lookup to Users table

    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,271 Most Valuable Professional on 16 Nov 2022 at 19:18:28
    Re: User() Function and Lookup to Users table

    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 16 Nov 2022 at 20:51:28
    Re: User() Function and Lookup to Users table

    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,271 Most Valuable Professional on 16 Nov 2022 at 22:06:29
    Re: User() Function and Lookup to Users table

    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 16 Nov 2022 at 22:16:25
    Re: User() Function and Lookup to Users table

    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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Chiara Carbone – Community Spotlight

We are honored to recognize Chiara Carbone as our Community Spotlight for November…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 629 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 397 Super User 2025 Season 2

#3
wolenberg_ Profile Picture

wolenberg_ 232 Moderator

Last 30 days Overall leaderboard
Loading complete