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

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
sharonsumner
Level: Powered On

Re: Patch patches old values

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

anotherlama
Level: Powered On

Re: Patch patches old values

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

sharonsumner
Level: Powered On

Re: Patch patches old values

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

 

 

 

anotherlama
Level: Powered On

Re: Patch patches old values

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
Better Together’ Contest Finalists Announced!

'Better Together’ Contest Finalists Announced!

Congrats to the finalists of our ‘Better Together’-themed T-shirt design contest! Click for the top entries.

thirdimage

Power Apps Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

sixthImage

Join THE global Microsoft Power Platform event series

Attend for two days of expert-led learning and innovation on topics like AI and Analytics, powered by Dynamic Communities

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

thirdimage

Microsoft Business Applications Virtual Launch

Join us for the Microsoft Business Applications Virtual Launch Event on Thursday, April 2, 2020, at 8:00 AM PST.

thirdimage

Community Summit North America

Innovate, Collaborate, Grow - The top training and networking event across the globe for Microsoft Business Applications

Top Solution Authors
Top Kudoed Authors
Users online (9,082)