cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
DonBo
Frequent Visitor

how to set variable for last value

I need to save a last value of a dropdown control and maintain the previous value as the dropdown control update to a new value.

 

Here is my meager attempt.  But this doesn't work.

 

If(Not(varTargetLang = varLastTargetLang), Set(varLastTargetLang, varTargetLang))

 

The last value needs to be stored even when the app is closed and reopened.  Thanks.

1 ACCEPTED SOLUTION

Accepted Solutions
v-xida-msft
Community Support
Community Support

Hi @DonBo ,

Could you please share a bit more about your scenario?

Do you want to store the last selected value within the Dropdown box?

 

Based on the needs that you mentioned, I think the OnSelect property of the Dropdown box and a Collection could achieve your needs.

I have made a test on my side, please take a try with the following workaround:

Set the OnSelect property of the Dropdown box to following:

ClearCollect(LastSelectedValue, Dropdown1.Selected.Value)

the last selected value would be stored within the LastSelectedValue collection.

 

If you want to save your Last selected from the Dropdown box even when close or re-open your app, I think the SaveData function and LoadData function could achieve your needs.

Please set the OnSelect property of the Dropdown box to following:

ClearCollect(LastSelectedValue, Dropdown1.Selected.Value);
SaveData(LastSelectedValue,"LocalData")

Set the OnStart property of the App control to following:

LoadData(LastSelectedValue, "LocalData", true)

Note: You can't use SaveData and LoadData function inside a browser, either when authoring the app in PowerApps Studio or when running the app in the web player. To test your app, run it in PowerApps Mobile on an iPhone or Android device.

 

More details about SaveData function, and LoadData function, please check the following article:

https://docs.microsoft.com/en-us/powerapps/maker/canvas-apps/functions/function-savedata-loaddata

 

Please take a try with above solution, check if the issue is solved.

 

Best regards,

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

2 REPLIES 2
dyee4614
Helper V
Helper V

I don't know if this is the best way to do this but here is what I did when I had a similar problem.  I created a collection and left the answer blank.  Whenever there was a selection made, I patched the value into my collection.  On my next page or submit or whatever, I set it to reset the value of that collection so it always returns to the default when you leave.  

 

The only way around the close/reopen issue I can think of is SaveData and LoadData.  You can use SaveData to save a copy of the data on your device locally and use LoadData to pull the last entry.  

 

Note: The first time someone uses the app, there will be nothing to load so you will get an error message.  This will go away after you save data for the first time. 

v-xida-msft
Community Support
Community Support

Hi @DonBo ,

Could you please share a bit more about your scenario?

Do you want to store the last selected value within the Dropdown box?

 

Based on the needs that you mentioned, I think the OnSelect property of the Dropdown box and a Collection could achieve your needs.

I have made a test on my side, please take a try with the following workaround:

Set the OnSelect property of the Dropdown box to following:

ClearCollect(LastSelectedValue, Dropdown1.Selected.Value)

the last selected value would be stored within the LastSelectedValue collection.

 

If you want to save your Last selected from the Dropdown box even when close or re-open your app, I think the SaveData function and LoadData function could achieve your needs.

Please set the OnSelect property of the Dropdown box to following:

ClearCollect(LastSelectedValue, Dropdown1.Selected.Value);
SaveData(LastSelectedValue,"LocalData")

Set the OnStart property of the App control to following:

LoadData(LastSelectedValue, "LocalData", true)

Note: You can't use SaveData and LoadData function inside a browser, either when authoring the app in PowerApps Studio or when running the app in the web player. To test your app, run it in PowerApps Mobile on an iPhone or Android device.

 

More details about SaveData function, and LoadData function, please check the following article:

https://docs.microsoft.com/en-us/powerapps/maker/canvas-apps/functions/function-savedata-loaddata

 

Please take a try with above solution, check if the issue is solved.

 

Best regards,

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

Helpful resources

Announcements
User Group Leader Meeting January 768x460.png

Calling all User Group Leaders!

Don't miss the User Group Leader meetings on January, 24th & 25th, 2022.

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

Top Solution Authors
Top Kudoed Authors
Users online (1,474)