cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Anonymous
Not applicable

Practices for retrieving data from Office365Users.MyProfile() once and using it through the PowerApp

I noticed that whenever I use Office365Users.MyProfile() function it makes calls every time I uses it, and I do use it quite a lot in my application (like on every screen few times). That slows down my app as every time it asks for same information and wait until it loads. I was wondering is it possible to call Office365Users.MyProfile() function once the App is launched and reuse that info through the app without calling it ever again (or keeping it while the users session is active so that it connects to Office365 network only once per user session). Is there any practices of how to create temporary variables which keep their record for individual sessions while the users is using the App?

 

I am looking for something like this:

On App Launch:

UsersProfile() = Office365Users.MyProfile();

And then instead of using Office365Users.MyProfile()

I could use UserProfile() instead which is local variable and does not connect to external data every time.

Any other tips for improving efficiency also welcome! Thanks!

1 ACCEPTED SOLUTION

Accepted Solutions
PowerApps Staff carlosag
PowerApps Staff

Re: Practices for retrieving data from Office365Users.MyProfile() once and using it through the Powe

The best way for me is using Context Variables. Basicailly you would do is add in the OnVisible of the first screen something like:

UpdateContext({UserProfile: Office365Users.MyProfile()})

From then on in that screen you can bind Labels to UserProfile.Mail, or UserProfile.DisplayName, etc.

 

If you need the same data in another screen, then when calling Navigate you can pass the context using the third argument like:

Navigate(Screen2, ScreenTransition.Fade, {UserProfile: UserProfile})

Then in that screen you will have UserProfile as well.

 

Another option if you don't like passing the context across screens is collecting it into a Collection since those are global, however it will be tedious and not very performant to do LookUp formulas like: LookUp(Globals, Name = "Profile").Value.DisplayName

 

So I would recommend using Context Variables as above. We are looking at supporting Global variables that will allow you to do something similar and not require to pass them through Navigate, but that is still not available.

 

 

View solution in original post

1 REPLY 1
PowerApps Staff carlosag
PowerApps Staff

Re: Practices for retrieving data from Office365Users.MyProfile() once and using it through the Powe

The best way for me is using Context Variables. Basicailly you would do is add in the OnVisible of the first screen something like:

UpdateContext({UserProfile: Office365Users.MyProfile()})

From then on in that screen you can bind Labels to UserProfile.Mail, or UserProfile.DisplayName, etc.

 

If you need the same data in another screen, then when calling Navigate you can pass the context using the third argument like:

Navigate(Screen2, ScreenTransition.Fade, {UserProfile: UserProfile})

Then in that screen you will have UserProfile as well.

 

Another option if you don't like passing the context across screens is collecting it into a Collection since those are global, however it will be tedious and not very performant to do LookUp formulas like: LookUp(Globals, Name = "Profile").Value.DisplayName

 

So I would recommend using Context Variables as above. We are looking at supporting Global variables that will allow you to do something similar and not require to pass them through Navigate, but that is still not available.

 

 

View solution in original post

Helpful resources

Announcements
thirdimage

Power Automate Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

sixthImage

Power Platform World Tour

Find out where you can attend!

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

fifthimage

Microsoft Learn

Learn how to build the business apps that you need.

Top Kudoed Authors (Last 30 Days)
Users online (5,893)