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

Patch patches old values

Hello! I have a sharepoint list that is supposed to track costs. The structure of my sharepoint list is as follows: I have a field for every cost category and for each of these categories I have a another field that contains the value prior to the last edit.
For example, the columns of my list are


CostCategoryA; CostCategoryA_PriorValue; CostCategoryB; CostCategoryB_PriorValue.


Lets say, I enter my costs when creating the item: CostCategoryA: 100$, CostCategoryB: 200$. At this point, the _priorValue fields would be empty. Now, I have an edit form in my app where i can update the entry. I will change the costs: CostCategoryA: 50$, CostCategoryB: 100$. The submit button holds the following code:

 

Patch(MyList; Gallery1.Selected; {CostCategoryA : DataCardValue1.Text; CostCategoryB : DataCardValue2.Text}

 

All of this works fine. Now, to realize the _priorValue fields, I added to the following code to the submit button: 

 

If(!(Gallery1.Selected.CostCategoryA= DataCardValue1.Text); Patch(MyList; Gallery1.Selected; {CostCategoryA_PriorValue : Gallery1.Selected.CostCategoryA}));;
If(!(Gallery1.Selected.CostCategoryB= DataCardValue2.Text); Patch(MyList; Gallery1.Selected; {CostCategoryB_PriorValue : Gallery1.Selected.CostCategoryB}));;

I added this code just before the other patch. What I try to achieve is a conditional patch: The _priorValue field should only be patched with the old values, if the values changed.

What happens now, is the following: The old value is indeed copied to the _priorValue field. However, the other field ("CostCategoryA/B") is not updated anymore. Without the if(patch()), I did however update.


It looks like this now: 
CostCategoryA: 100$; CostCategoryA_PriorValue; 100$ ; CostCategoryB: 200$; CostCategoryB_PriorValue:200$
It is supposed to look like this:

CostCategoryA: 50$; CostCategoryA_PriorValue; 100$ ; CostCategoryB: 100$; CostCategoryB_PriorValue:200$

 

I think, the problem is the if(patch()) part...  Any ideas on this? 

4 REPLIES 4

Hi

 

It may be simpler to write the values of the current prices to variables on form load, then on patch if there is a change to the current value write these to the Prior column. 

 

Sharon

Anonymous
Not applicable

Hi sharon, thanks for your reply! By "write" you mean that I should use patch? @sharonsumner 

Hey

 

Yes, patch them as well, it just takes the logic out of a complex nested patch. 

 

There are some great videos in the community on patching and nested patching, here are a few, I'd reccommend both Shane Youngs and Laura Rogers as great presenters for this; 

 

https://www.youtube.com/results?search_query=nested+patching+powerapps

 

 

 

Anonymous
Not applicable

Hey @sharonsumner 
Thanks again for your help. I restructured the whole thing. The onVisible Property of the Form screen now holds the Set() function for the variables:

Set(CostCategoryA_Selected: Gallery1.Selected.CostCategoryA);;Set(CostCategoryB_Selected: Gallery1.Selected.CostCategoryB)

The Submit Button now looks like this:

If((CostCategoryA_Selected = DataCardValue1.Text); Patch(ViComMain; Gallery1.Selected; {CostCategoryA_PriorValue : ""}); Patch(ViComMain; Gallery1.Selected; {CostCategoryA: DataCardValue1.Text; CostCategoryA_PriorValue: CostCategoryA_Selected}));;

Now, a really weird thing is happening: For the CostCategory fields (number fields) the thing still dont works. CostCategory still holds the same, old, value and the _PriorValue field is neither blanked nor updated. However, next to the number fields, I also have columns in my list that contain text. For these columns, the code is working and the new values are patched. The blank, however, also does not work here. Any ideas..... ?

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.

Community Call Conversations

Introducing the Community Calls Conversations

A great place where you can stay up to date with community calls and interact with the speakers.

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 (5,837)