cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
MD2409_
Helper I
Helper I

Complition Handling with Patch Command

Hello,

 

imagen a powerapp with multiple input tab and fields and a save button. Behind this button i have a patch command which update multiple tables in dataverse. Combined with the Patch action i have a error handling which prevent a bad data quality. Fine so far.

 

But how could i bring a kind of transaction or Complition Handling in place to get sure everthing is saved successfully.
The experience in the past wasn't that good so we face some update issues because the patch process from time to time do not update all tables ....

One option we discussed was a powerautomate but this couldn't be the solution. Is there any kind of "inbuild" solution / mechanisms to handle this ?

 

Best regards MD

1 ACCEPTED SOLUTION

Accepted Solutions
Pstork1
Dual Super User III
Dual Super User III

In this case there would be nothing to do since you are creating a new record.  With a new record there is nothing to back out.

 

But let's say you are patching two tables with edits.  One of the patches fails.  Then the record for the patch that succeeded will need to be re-patched with the original values to roll back the patches.  Nothing will need to be done with the one that failed because it failed. Restoring the original values will require temporarily storing the previous values somewhere so they can be put back.  This all becomes very complicated in Power Apps and it gets worse with every additional patch.  

 

Because Power Automate is procedural it is still complex but a bit more manageable.



-------------------------------------------------------------------------
If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.

View solution in original post

7 REPLIES 7
Pstork1
Dual Super User III
Dual Super User III

There is no built in support for transactions.  So your only real choice is to save the existing data for the record being patched from each of the tables and re-apply it if any of the updates fail.  Since Power Apps is a declarative system this is more difficult to do in Power Apps than it would be in Power Automate where actions are procedural.  But it should be possible in either system.  Each Patch() statement will return a boolean if it succeeds or fails.  you need to check that all Patches returned true.  If not you need to Patch the original records back in place.



-------------------------------------------------------------------------
If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.

Thx for your response how i could check the return value of each patch statement?
Is it recommended to have only once for all tables or multiple, one for each table?

 

Is there any architectural option to handle this in a better way than with patch and the error handling of it?

 

Pstork1
Dual Super User III
Dual Super User III

You have to patch each table separately.  But the patch() will return a value signifying whether it was successful or not.  You can capture that value in a variable.

 

Set(PatchResult, Patch(.....

 

PatchResult will be true if the Patch was successful and false if it wasn't.

 

As I said, Power Automate is procedural and has some capability to do error checking.  But other than that there isn't really a lot you can do.



-------------------------------------------------------------------------
If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.

How i could handle this with this example.
Check the patchresult and how could be the reaction if the result ist NOK

Patch(YPC_Head;Defaults(YPC_Head);{IDypc:myNewIDypc; VBELN:myNewVBELN; POSNR:myNewPOSNR; KMAT_P22:myKMATP22; KMAT:myKMAT; ERDAT:Now(); YPCversion: myYPCversion; KWMENG:myKWMENG; NETWR:myNETWR; VA00:myVA00; EK02:myEK02; SKA:mySKA; SWSK:mySWSK; ConfigText: myConfigTextHead; UserID:myUser; Information:myInfo; StatusYPC:myIDypcStatus; StatusID:myStatusID; IDcopy:myIDcopy});
Set(myNewSDstatus;"Duplicate")

Pstork1
Dual Super User III
Dual Super User III

Set(patcherrormPatch(YPC_Head;Defaults(YPC_Head);{IDypc:myNewIDypc; VBELN:myNewVBELN; POSNR:myNewPOSNR; KMAT_P22:myKMATP22; KMAT:myKMAT; ERDAT:Now(); YPCversion: myYPCversion; KWMENG:myKWMENG; NETWR:myNETWR; VA00:myVA00; EK02:myEK02; SKA:mySKA; SWSK:mySWSK; ConfigText: myConfigTextHead; UserID:myUser; Information:myInfo; StatusYPC:myIDypcStatus; StatusID:myStatusID; IDcopy:myIDcopy}));

Then have an error label with visible = to 

If(patcherror,true,false)

But that is just trying to create a new record in one table.  There would be a lot more involved if you want to also back out the entries in other tables.



-------------------------------------------------------------------------
If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.

Hi,

thx for your response, but what could be the action if the return is false?

What you mean with "back out the entries in other tables" ? Do you talking about deleting entries?
What is the required action in this case?

 

Thx

Pstork1
Dual Super User III
Dual Super User III

In this case there would be nothing to do since you are creating a new record.  With a new record there is nothing to back out.

 

But let's say you are patching two tables with edits.  One of the patches fails.  Then the record for the patch that succeeded will need to be re-patched with the original values to roll back the patches.  Nothing will need to be done with the one that failed because it failed. Restoring the original values will require temporarily storing the previous values somewhere so they can be put back.  This all becomes very complicated in Power Apps and it gets worse with every additional patch.  

 

Because Power Automate is procedural it is still complex but a bit more manageable.



-------------------------------------------------------------------------
If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.

View solution in original post

Helpful resources

Announcements
UG GA Amplification 768x460.png

Launching new user group features

Learn how to create your own user groups today!

Power Apps Community Call Jan. 2022 768x460.png

Power Apps Community Call

Please join us on Wednesday, January 19th, at 8a PDT. Come and learn from our amazing speakers!

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,646)