Bhubaneswar, Odisha, India
+91-8328865778
support@softchief.com

Create or Update records without using Forms in Canvas Apps using Patch function

Create or Update records without using Forms in Canvas Apps using Patch function

When we build canvas apps in Power Apps, we add Galleries to display records from our data source and Forms to view, create, and edit individual records, but sometimes forms are not enough to achieve our business scenarios. For those scenarios, We use Power Apps functions for updating tabular data sources directly.

Patch is used when you want to update data source directly without using forms. Lets take a scenario. For example you want to update a log table data source every time a user clicks a button to navigate to another screen you could use the formula for the OnSelect property of the button.

The below is the table with two fields.

The Canvas Apps is connected to table and created two screens with one buttons. When the user is on main screen and after filling the contact details and clicking Next button to go second screen I want to log some information so we have to call Patch function as below. Call the function on Select property.

The below Power FX can be used to create record.

Patch('Log Tables', Defaults('Log Tables'), {'Clicked User': User().FullName, 'Clicked Time': Now()}); 
Navigate(secondscreen, ScreenTransition.Cover)

Now you will see the details saved in table.

To Edit or Update Record you can use below formula:

Patch(Orders, LookUP(Orders, ID = 1), {Region: "Asia", Country: "China"})

Update all records using below formula

Patch(CustomerOrders, Default(CustomerOrders), {Status: "Pending"})

Delete Record:

Remove(CustomerOrders, LookUp(CustomerOrders, ID = 1))

Delete Based on Condition

RemoveIf(CustomerOrders, Status = “Expired”)

Delete Records of a Collection:

Clear(collectSelectedItems)

Conditional Delete

RemoveIf(CustomerOrders, true)

Hope this helps

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