<img height="1" width="1" style="display:none" src="https://www.facebook.com/tr?id=612681139262614&amp;ev=PageView&amp;noscript=1">
Skip to content

Need help? Talk to an expert: phone(904) 638-5743

Power Apps 101: Deleting Records in Canvas Apps

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 OnSelect property 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:

  1. Add a Container: Insert a free-flowing container for flexibility.
  2. Customize Visibility: Rename the container CNT_ConfirmDelete and adjust its fill color for visibility.
  3. 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 UpdateContext function to manage the variable.
  • Set the variable VarShowConfirmScreen to false by default in the screen's OnVisible property.
  • Update the variable to true when 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 UpdateContext to 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 Visible property 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

Leave a comment

Free Community Plan

On-demand learning

Most Recent

private training

Hackathons, enterprise training, virtual monitoring