cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
csm
Helper I
Helper I

Store user settings

Hello,

 

I would like to store user settings per device in an app I am building. For example, if they select an option in a dropdown, I would like to display the same option next time they open the app. I would also like to save the settings per devices that user may use, so I can't save the settings against the user in a cloud database.

 

The two ways I have considered are:

1. Save the settings locally in the device the user is using, however I cant find any way to store these once you close the app.

2. Save the settings in CDM against the device name, however I can't find any way to identify the device name using the powerapps formulas.

 

Is there any way to do either of these, or any other way to achive what I am trying to do?

 

Thanks

1 ACCEPTED SOLUTION

Accepted Solutions
Meneghino
Community Champion
Community Champion

Hello @csm

 

Alternative 1

 

To store settings locally in the device you can use the SaveData and LoadData functions, please see here:

https://powerapps.microsoft.com/en-us/tutorials/function-savedata-loaddata/

 

"Storage is encrypted and in a private location on the local device, isolated from other users and other apps."

 

Please let me know if you have difficulties implementing this.

 

Alternative 2

 

You can store settings in CDS (new name for CDM) but not against the device but against the user.  For example you can get the user name or email with the User function.

https://powerapps.microsoft.com/en-us/tutorials/function-user/

You can also use Office365 identities.

 

Again, please let me know if you need help with this.

View solution in original post

20 REPLIES 20
Perumal
Continued Contributor
Continued Contributor

I don't find option to get the device name currently in PowerApps. Consider posting this in PowerApps Ideas.

Meneghino
Community Champion
Community Champion

Hello @csm

 

Alternative 1

 

To store settings locally in the device you can use the SaveData and LoadData functions, please see here:

https://powerapps.microsoft.com/en-us/tutorials/function-savedata-loaddata/

 

"Storage is encrypted and in a private location on the local device, isolated from other users and other apps."

 

Please let me know if you have difficulties implementing this.

 

Alternative 2

 

You can store settings in CDS (new name for CDM) but not against the device but against the user.  For example you can get the user name or email with the User function.

https://powerapps.microsoft.com/en-us/tutorials/function-user/

You can also use Office365 identities.

 

Again, please let me know if you need help with this.

Thanks @Meneghino, option 1 works perfectly. Exactly what I was looking for.

 

One question, is there any way to see if the file exists before calling LoadData? It's not a big issue, however the app throws an error the first time its used as it cannot find the file.

Meneghino
Community Champion
Community Champion

I think the error can be avoided, but I would need more details about when you save/load in your app and when the error is thrown.

What I am trying to achieve is that a certain dropdown defaults to the same value the user selected when last using the app.

 

Currently I ClearCollect then SaveData using the dropdown OnChange action:

ClearCollect(UserSettings, {Area: AreaDropdown.Selected.Value}); SaveData(UserSettings, "LocalSettings")

Then using the screen OnVisible action, I am loading the collection:

LoadData(UserSettings, "LocalSettings")

Finally, the Default property of the dropdown is the Area from UserSettings:

First(UserSettings).Area

The issue is only prior to being set the first time. The screen OnVisible event triggerst he error because the collection has never been saved to the local device.

 

Thanks 

Meneghino
Community Champion
Community Champion

Thanks for the clear reply and explanation.

I have reproduced the error (see screenshot below), but it doesn't actually show up as an error to the user or stop execution of the app.  Please let me know if it is different in your case.

 

CaptureLoadError.JPG

 

It is not very elegant, but I would just ignore the error that is shown in design mode.

What you can do to deal with the default value in case it is the first time the app is used on a device, is to do this:

MyDropDown.Default = If(IsEmpty(UserSettings), "XXX", First(UserSettings).Area)

Where "XXX" is the value you want to show the first time the app is used on a new device.

Has this helped?

@Meneghino, unfortunately I am getting an error shown to the user in the app. See below:

Capture.PNG

 

I don't believe your suggestion will help, as the error is shown when trying to execute the LoadData formula, which is nothing to do with the dropdown at that point.

 

What would fix the issue would be something like the following, if "DataExists" was a formula:

If(DataExists(LocalData), LoadData(UserSettings, "LocalSettings"), ClearCollect(UserSettings, {Area: AreaDropdown.Selected.Value}))

 

 

Meneghino
Community Champion
Community Champion

Hi @csm, if the error is shown to the user in your device, then I fully agree.

This seems to be a logical inconsistency.

Thanks, csm.  I filed a ticket with the product team to provide a way to ignore a missing file in LoadData.  That would solve your issue, correct?

Helpful resources

Announcements
Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

May UG Leader Call Carousel 768x460.png

June User Group Leader Call

Join us on June 28 for our monthly User Group leader call!

PA Virtual Workshop Carousel 768x460.png

Register for a Free Workshop

This training provides practical hands-on experience in creating Power Apps solutions in a full-day of instructor-led App creation workshop.

PA.JPG

New Release Planning Portal (Preview)

Check out our new release planning portal, an interactive way to plan and prepare for upcoming features in Power Platform.

Top Solution Authors
Users online (1,439)