PowerApps User() function – cache current user OnStart

The User() function currently gets called by your app every time it is used.  This can cause you app to slow down, or expressions with User() to not work at all.  The quick answer is to cache the current user in a global variable when the app starts.

This can be done by setting the home screen’s OnStart property to this:

Set(CurrentUser, User())

Then anywhere in the app, just use CurrentUser just as you would User()

For example to filter a data source by the current user, you would use someting like this:

Filter(MyTable, User_email_column = CurrentUser.Email)

  • Once you set the OnStart property you need to save/close and re-open the app in order for the OnStart property actions to be executed
  • CurrentUser will be a record type variable
  • You can always check if the variable is set properly by creating a label and setting its text property to:
    CurrentUser.Email
    or
    CurrentUser.FullName
  • Don’t forget that PowerApps is case sensitive.  Use the Lower() function to remove capitalisation when making comparisons that need not be case sensitive
  • See the User() function documentation

3 Replies to “PowerApps User() function – cache current user OnStart”

  1. Thank you!

    I am not running into case sensitivity issues.

    I used flow to update Sharepoint list for Email_Column from Created By column, which seems to hold the correct case in place.

  2. I have a couple of questions,

    Can you set a global variable for OnStart property to
    Set(CurrentUserEmail, User().Email)

    And when you would apply filter for a gallery,

    Filter(MyTable, User_Email_Column = CurrentUserEmail)

    I’ve used your instructions, saved my PowerApp, closed and reopened the PowerApp however it is not filtering the gallery.items

    Still confused on how case sensitivity plays a role with filters.

    Thanks!

    1. Yes, you can set the global variable with the formula you provided. You can always check by creating a label with Text property:
      "Welcome "&User().Email
      In order to avoid the issue of case sensitivity, you can use the Lower() function, so that for the OnStart property you do this:
      Set(CurrentUserEmail, Lower(User().Email))
      and ensure that User_Email_Column contains the email addresses all in lower case.

Leave a Reply

Your email address will not be published. Required fields are marked *