In this episode of the Power Platform series, Matt Peterson, Senior Trainer at Pragmatic Works, explores a powerful and practical use case of the Patch function in Power Apps: updating records and implementing a soft delete mechanism. Building on concepts introduced in previous lessons, Matt demonstrates how developers can move beyond basic record creation and leverage Patch to safely manage and modify existing data without permanently deleting it.
Matt begins by explaining that while Patch is commonly used to create new records without relying on forms, it also plays a crucial role in updating existing records. By attaching Patch to an OnSelect action—such as a button or icon—developers can dynamically update specific fields within a record.
This flexibility makes Patch ideal for scenarios where controlled updates are needed, especially when working with user interactions in apps.
One of the key challenges discussed is the risk associated with permanently deleting records. Traditional delete operations remove data entirely, which can lead to accidental loss—especially in user-driven applications.
Matt highlights a relatable scenario where a simple misclick could permanently remove important data. To mitigate this risk, he introduces the concept of a soft delete.
A soft delete allows developers to mark a record as inactive instead of removing it from the data source. This approach ensures that:
In Matt’s example, a SharePoint list is used as the data source, containing a simple Yes/No column labeled Active Record.
To achieve the soft delete behavior, Matt replaces the traditional Remove() function with a Patch statement. This allows him to update the selected record instead of deleting it.
The Patch logic follows three key components:
ThisItemIn this case, the Active Record column is updated from true to false, effectively marking the record as inactive.
Once implemented, clicking the icon updates the record instantly, demonstrating how Patch can efficiently modify data in real time.
To make the application more user-friendly, Matt adds conditional logic to display “Yes” or “No” instead of raw boolean values. This improves readability and helps users better understand the record status.
This step highlights the importance of combining data logic with UI enhancements to create intuitive applications.
After marking records as inactive, the next step is to hide them from the user interface. Matt achieves this by updating the gallery’s Items property using a Filter function.
The filter ensures that only records with Active Record = true are displayed.
This approach provides several advantages:
As a result, users only see active records, while inactive ones remain stored in the backend.
To further enhance the user experience, Matt introduces a notification using the Notify() function. This provides immediate feedback when a record is “deleted” (soft deleted).
Even though the record isn’t permanently removed, the notification helps maintain user expectations and clarity.
This session delivers several important insights for Power Apps developers:
Matt Peterson provides a clear and practical demonstration of how to use Patch for updating records and implementing a soft delete strategy in Power Apps. By replacing destructive actions with controlled updates, developers can build more reliable, user-friendly applications.
This approach not only safeguards data but also enhances overall application design, making it a valuable technique for anyone working within the Microsoft Power Platform ecosystem.
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.