Update all changes of a collection into Data Source from Canvas App Power Apps
Collection is a better way to store local data without connecting data source directly. This makes apps faster. But if you forget to update to actual data source, the changes done to the collection data, you will loose all updates once you close the app.
So its very important to send collection updates back to actual data source. In this post you will know the options available to update source from collection.
Using Collect function to update
If the columns name of actual data source are same with your collection variable then you can use Collect method to update collection data to source.
Collect(YourDataSource, collectMyFirstCollection)
Lets take an example we have a loan entity with some columns in Dataverse. The loan records bound to gallery to display data. Loan Number bound to a label, Customer name bound to a label but amount is bound to a textbox so that we can edit. Take a button called update Source.
The requirement is to update all loan record amount to 65000. So you can change the amount for all records using the text box and in update source on select property, use below function to update source with the collection changes.
but before that define a collection object and bind to the gallery. On Start property of the app add Clear Collect.
ClearCollect(colLoan,Loans)
This powerfx will initialize a collection variable to store loans info and bound to gallery.
The Run On Start option will load the collection data into gallery.
In the update source button use following code. Collect(Loans,col
Now you will see all records from collection.
You can use ForAll powefxalso
ForAll(Filter(colLoan, ThisItem> 60000), Patch(Loans, Defaults(Loans), {hdfc_name: Name, Amount: 50000}))
Hope this helps.
For more info read this article.
https://learn.microsoft.com/en-us/training/modules/work-with-external-data/4-move-data-using-collect
Follow my blog for more trending topics on Dynamics 365, Azure, C#, Power Portals and Power Platform. For training, Courses and consulting, call to us at +91 832 886 5778 I am working more for community to share skills in Dynamics 365 and Power Platform. Please support me by subscribing my YouTube Channel. My YouTube Channel link is this : https://www.youtube.com/user/sppmaestro