Power Apps 101: Deleting Records in Canvas Apps
In a recent episode of Power Apps 101 from Pragmatic Works, the focus was on deleting records in Canvas Apps while ensuring proper user confirmation to prevent accidental data loss.
Deleting Records the Simple Way
The simplest way to delete a record in a Canvas App involves using the Remove() function. The tutorial demonstrates how to:
- Add a trash can icon.
- Set the
OnSelectproperty to:Remove(PTORequestTable, ThisItem). - Test the deletion with a click on the icon.
However, this basic method permanently deletes the data without confirmation, which can lead to unintentional loss.
Adding a Confirmation Screen
To safeguard against accidental deletion, the video explains how to create a confirmation screen with a user prompt before data removal.
Steps to Create the Confirmation Screen:
- Add a Container: Insert a free-flowing container for flexibility.
- Customize Visibility: Rename the container
CNT_ConfirmDeleteand adjust its fill color for visibility. - Add Text and Buttons: Insert a label with a confirmation message and two buttons: "Confirm" (green) and "Cancel" (red).
Managing Visibility with Contextual Variables
The visibility of the confirmation screen is controlled using a contextual variable. The tutorial explains how to:
- Use the
UpdateContextfunction to manage the variable. - Set the variable
VarShowConfirmScreentofalseby default in the screen'sOnVisibleproperty. - Update the variable to
truewhen the trash icon is clicked. - Control the visibility property of the container using the variable.
Cancel Button Functionality
The Cancel button hides the confirmation screen by resetting the variable back to false:
UpdateContext({VarShowConfirmScreen: false})
Confirm Button Setup and Deleting the Record
The confirm button needs to both delete the record and hide the confirmation screen. To achieve this:
- Use
UpdateContextto reset the variable. - Use
Remove()to delete the record:
UpdateContext({VarShowConfirmScreen: false});
Remove(PTORequestTable, Gal_PTORequest.Selected)
Key Consideration: The Selected property is used instead of ThisItem because the container doesn't hold the original record directly.
Final Testing and Results
By following these steps, the confirmation screen properly appears when the trash icon is clicked. The user can choose to cancel or confirm deletion, ensuring better data protection.
Key Takeaways:
- Use the
Remove()function for direct deletion. - Implement a confirmation screen using contextual variables.
- Control visibility with the
Visibleproperty and variables. - Ensure both deletion and screen hiding occur when confirming.
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