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.
The simplest way to delete a record in a Canvas App involves using the Remove() function. The tutorial demonstrates how to:
OnSelect property to: Remove(PTORequestTable, ThisItem).However, this basic method permanently deletes the data without confirmation, which can lead to unintentional loss.
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:
CNT_ConfirmDelete and adjust its fill color for visibility.The visibility of the confirmation screen is controlled using a contextual variable. The tutorial explains how to:
UpdateContext function to manage the variable.VarShowConfirmScreen to false by default in the screen's OnVisible property.true when the trash icon is clicked.The Cancel button hides the confirmation screen by resetting the variable back to false:
UpdateContext({VarShowConfirmScreen: false})
The confirm button needs to both delete the record and hide the confirmation screen. To achieve this:
UpdateContext to reset the variable.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.
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.
Remove() function for direct deletion.Visible property and variables.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.