11-10-2023 08:52 AM - last edited 12-19-2023 12:03 PM
About
Patch multiple rows in Power Apps like a Jedi!
Using the Patch function in Power Apps is a common way to create and edit multiple rows of data in a data source. There are different ways to use patch, so this sample app gives a detailed overview on three methods:
1) For All
2) Schema matching / Upsert
3) JSON / Parse JSON
Breakdown
Each method has its own screen, where you can understand the performance when used against 100 rows of sample data:
Navigate through the app using the buttons in the bottom right to test each method, and see snippets of the Power Fx code.
Install
Download the PatchMultipleRecordsExamples_1_0_0_2.zip file, then follow this Microsoft Learn Article to import the solution into your chosen environment. Play the app to interact with the walkthrough functionality.
The solution is unmanaged, so you can open in edit mode to see the underlying code and patterns.
License
The solution contains x3 Dataverse tables. Please import the solution into an environment where you have access to interact with Dataverse. You can create a developer environment which gives you access to Dataverse without needing a Power Apps Premium license.
Shoutout
To @RandyHayes for reaching out and providing extra context and guidance with the ForAll approach. Solution updated to reflect his excellent knowledge on this subject.
Update
19/12/23 - updated with a few minor code tweaks/improvements.
------------------------------------------------------------------------------------------------------------------------------
Feel free to visit my blog for weekly tips!
https://platformsofpower.net
Love this article! These are great techniques that I had no idea about.
When it comes to the Schema Match method, I'm confused about why we can leave out both the Defaults() and {ID:ID} from the patch? How does it know when to update existing items vs create new ones? Is this only available for Dataverse data sources or would SharePoint be able to use this as well?
Hi @bspang ,
I think it's largely around how it's designed behind the scenes to process a single record at a time, versus processing in bulk as a batch. Microsoft's documentation doesn't give too many hints, other than the fact that's it's possible (same link but bit further down). Minimum requirement is to have the unique ID of the row present, so you ALWAYS need that relevant column to make it work; it will then create new items, modify existing ones it finds and ignores the rest. Very efficient.
Yes, it works for Dataverse, SharePoint, SQL etc 🚀