cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
sperry1625
Solution Supplier
Solution Supplier

Updating Memory Variables

This is a general question which I think I know the answer to but have seen inconsistent results.

 

In many of the SharePoint Power Apps that I build I load the SP data the user is editing into a variable:

Set( gblRequest, LookUp( 'Requests', ID = SharePointIntegration.SelectedListID ) );

I then set the Forms Item property to this variable.  Generally works well.

There are occasions where an action by the user will require me to update a property in that variable that is different than the one tied to the field the user is currently editing, maybe in an OnChange() event.  This is how I have been doing that:

Set(
    gblRequest,
    Patch(
        gblRequest,
        {
            Status: { Value: "Changed" }
        }
    )
);

 

This is a simple example, but should give you an idea of what I am doing.

So my question is, is this correct? Will this always have the expected outcome?

I have seen instances where I have a Drop Down that is tied to one property in the variable (gblRequest in this example). When the user changes the value of that drop down I need to force a reset on two other fields in the variable.  I do that in the OnChange() for the drop down.  What I see when that happens is the reset works, but the drop down value gets reset back to it's original value.

 

Not 100% sure what is going on here.

 

Anything to help solve this would be appreciated.

 

Thanks.

Regards,

-S

Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

1 ACCEPTED SOLUTION

Accepted Solutions
RandyHayes
Super User
Super User

@sperry1625 

Your method for setting the variable is correct and the method to change it is correct.


In regard to controls with Items properties (dropdown, combobox, Gallery, etc).  When you change anything that is related to the Item property of the control (as in the above changing of a variable) the formula on the Items will re-evaluate itself.  This is why all of those controls have a Default property (DefaultSelectedItems in the case of a combobox).  This is where you "retain" the item that is selected.  Otherwise you are expecting PowerApps to retain the selection for you.  If the Items formula is a simple formula (no data shaping, no searching, etc) then it will retain it for you, otherwise it will reselect the first item in the Items property table.  Best to always use the default properties to get what you want accurate.

 

I hope this is helpful for you.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
NOTE: My normal response times will be Mon to Fri from 1 PM to 10 PM UTC (and lots of other times too!)
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

View solution in original post

1 REPLY 1
RandyHayes
Super User
Super User

@sperry1625 

Your method for setting the variable is correct and the method to change it is correct.


In regard to controls with Items properties (dropdown, combobox, Gallery, etc).  When you change anything that is related to the Item property of the control (as in the above changing of a variable) the formula on the Items will re-evaluate itself.  This is why all of those controls have a Default property (DefaultSelectedItems in the case of a combobox).  This is where you "retain" the item that is selected.  Otherwise you are expecting PowerApps to retain the selection for you.  If the Items formula is a simple formula (no data shaping, no searching, etc) then it will retain it for you, otherwise it will reselect the first item in the Items property table.  Best to always use the default properties to get what you want accurate.

 

I hope this is helpful for you.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
NOTE: My normal response times will be Mon to Fri from 1 PM to 10 PM UTC (and lots of other times too!)
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

Helpful resources

Announcements
Power Apps News & Annoucements carousel

Power Apps News & Announcements

Keep up to date with current events and community announcements in the Power Apps community.

Power Apps Community Blog Carousel

Power Apps Community Blog

Check out the latest Community Blog from the community!

Top Solution Authors
Top Kudoed Authors
Users online (2,576)