cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
csm
Level: Powered On

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
Level 10

Re: Store user settings

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

18 REPLIES 18
Perumal
Level 10

Re: Store user settings

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

Meneghino
Level 10

Re: Store user settings

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

csm
Level: Powered On

Re: Store user settings

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
Level 10

Re: Store user settings

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.

csm
Level: Powered On

Re: Store user settings

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
Level 10

Re: Store user settings

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?

csm
Level: Powered On

Re: Store user settings

@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
Level 10

Re: Store user settings

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

This seems to be a logical inconsistency.

Highlighted
PowerApps Staff Chris
PowerApps Staff

Re: Store user settings

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
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
Users Online
Currently online: 205 members 5,612 guests
Please welcome our newest community members: