Power Apps 101 | Learn How Search and Filters for Canvas Apps Works!
Power Apps 101: Patch Tutorial
Matt Peterson walks us through using the Patch function in Power Apps to update records without relying on forms. This tutorial focuses on scenarios where developers need to update records directly from galleries or through actions like soft deletes, making it a practical approach for building Power Apps without traditional forms.
Introduction to the Patch Function
Power Apps offers a powerful function called Patch that enables developers to modify or create records without the need for a form. In this tutorial, Matt demonstrates how to use this function to update records in the DataVerse environment, specifically to perform soft deletes and update status values.
Soft Deleting Records with Patch
Matt begins by showing how to handle a common scenario: updating a record’s status to inactive (soft delete) without removing it from the database. The steps to do this are outlined as follows:
- Select the record you wish to update from the gallery.
- Use the
Patchfunction to update the selected record’s status field to 'inactive' rather than deleting it. - By using this method, the record disappears from the gallery, but it remains in the database for historical tracking.
Creating the Patch Function
To begin with the Patch function:
- Step 1: Identify the data source (in this case, the PTO request table).
- Step 2: Specify the record to update by referring to the selected item in the gallery.
- Step 3: Update the record's status using a choice list, setting the value to 'inactive.'
Matt demonstrates this with the following formula:
Patch(PTORequestTable, SelectedRecord, {Status: {Value: "Inactive"}})
Visualizing the Soft Delete
Once the Patch function is applied, the status of the selected record changes to 'inactive,' and the record disappears from the gallery, simulating a soft delete. This method is useful for preserving historical data while keeping the interface clean and user-friendly.
Filtering the Gallery
In addition to updating the record, Matt also shows how to filter the gallery to display only active records. By applying a filter based on the record status, users will only see active records in the gallery:
Filter(PTORequestTable, Status.Value = "Active")
This filtering ensures that inactive records are not displayed in the gallery, enhancing the user experience.
Handling Approvals and Rejections
Matt goes on to show another common use case for the Patch function: updating a record's approval status. For example, when a manager approves or rejects a PTO request, the status can be updated without using a form.
To implement this, Matt adds a button to the gallery, and when clicked, the button triggers a Patch function to update the PTO request’s status to either 'approved' or 'rejected.'
Summary of Key Steps
- Use the
Patchfunction to update records based on user actions. - Perform soft deletes by updating the status field to 'inactive.'
- Filter galleries to display only active records.
- Update approval statuses directly through buttons without forms.
Conclusion
Matt concludes by encouraging viewers to experiment with the Patch function to make their Power Apps more efficient and dynamic. Additionally, Pragmatic Works offers virtual mentoring services for developers looking to refine their apps. Matt invites viewers to leave comments or suggest future topics for upcoming tutorials.
Don't forget to check out the Pragmatic Works' on-demand learning platform for more insightful content and training sessions on Power Apps and other Microsoft applications. Be sure to subscribe to the Pragmatic Works YouTube channel to stay up-to-date on the latest tips and tricks.
Sign-up now and get instant access
ABOUT THE AUTHOR
Matt Peterson is a Trainer for Pragmatic Works specializing in the Power Platform. He graduated from the University of North Florida in 2006 and comes with 15 years of teaching experience in high school algebra. Matt earned the accomplishment in 2013 of being named the Florida Gifted Teacher of The Year. His primary focus is helping our customers learn the ins and outs of Power Apps and Power BI.
Free Community Plan
On-demand learning
Most Recent
private training

Leave a comment