Editing and Deleting Records in a Power Apps Form – Complete Guide
📌 Introduction
Editing and deleting records are fundamental functionalities when working with forms in Power Apps. Whether updating an existing record or removing unwanted data, proper implementation ensures a seamless user experience.
This guide covers:
✔ How to set up an Edit Form to modify records
✔ How to configure a Delete Button to remove records
✔ How to use functions like Patch(), Remove(), RemoveIf()
✔ Best practices for managing data integrity and user experience
🔹 Step 1: Understanding the Form Control for Editing and Deleting
Power Apps provides a Form Control that can be used to edit existing records.
✅ Types of Forms in Power Apps
Form Type | Purpose |
---|---|
Edit Form | Allows users to modify existing records. |
New Form | Enables users to create a new record. |
View Form | Displays records in a read-only mode. |
For editing and deleting, we primarily work with the Edit Form.
🔹 Step 2: Adding an Edit Form to Your Power App
✅ Step 1: Insert the Edit Form
- Open Power Apps Studio and create a new app or edit an existing one.
- Click on Insert > Forms > Edit Form.
- Position the form on the screen.
✅ Step 2: Connect the Form to a Data Source
- Select the form and go to the Properties Panel.
- Under Data Source, select a data source (e.g., SharePoint, SQL, Excel, Dataverse).
- Click Edit Fields and select the fields you want to display.
📌 Example: Connecting to a SharePoint List named “EmployeeRecords”
🔹 Step 3: Displaying Data in the Edit Form
To edit records, the Edit Form needs to display a selected record.
✅ Selecting a Record for Editing
To select a record from a Gallery and load it into the form:
- Insert a Gallery control (
Insert > Gallery > Vertical
). - Set the Items property to:
EmployeeRecords
- Select the Edit Form and set the Item property to:
Gallery1.Selected
📌 Behavior: When a user selects a record in the gallery, it loads into the form for editing.
🔹 Step 4: Editing a Record in Power Apps Form
✅ Step 1: Add a Submit Button
- Insert a Button (
Insert > Button
). - Set its Text property to
"Update Record"
. - Set its OnSelect property to:
SubmitForm(EditForm1)
📌 Behavior: Saves the changes made in the form back to the data source.
✅ Step 2: Adding a Success Notification
To notify users of a successful update, modify the OnSuccess property of the form:
Notify("Record updated successfully!", NotificationType.Success)
📌 Behavior: Shows a success message after a successful update.
🔹 Step 5: Deleting a Record from the Data Source
Deleting a record requires using the Remove() function.
✅ Step 1: Add a Delete Button
- Insert a Button (
Insert > Button
). - Set its Text property to
"Delete Record"
. - Set its OnSelect property to:
Remove(EmployeeRecords, Gallery1.Selected)
📌 Behavior: Removes the selected record from the EmployeeRecords data source.
✅ Step 2: Confirm Deletion Before Proceeding
To prevent accidental deletions, prompt the user for confirmation.
Modify the OnSelect property:
If(
Confirm("Are you sure you want to delete this record?", "Yes", "No"),
Remove(EmployeeRecords, Gallery1.Selected)
)
📌 Behavior: Asks for confirmation before deleting a record.
🔹 Step 6: Handling Form Reset and Navigation
After editing or deleting, reset the form and navigate accordingly.
✅ Step 1: Reset the Form After Submission
Modify the OnSuccess property of the form:
ResetForm(EditForm1);
Navigate(Screen1, ScreenTransition.Fade)
📌 Behavior: Resets the form and navigates back to the main screen.
✅ Step 2: Refresh Data After Deletion
After a record is deleted, refresh the data source:
Refresh(EmployeeRecords)
📌 Behavior: Updates the gallery to reflect the changes.
🔹 Step 7: Using Patch() for Editing Instead of Forms
The Patch() function can be used as an alternative to SubmitForm().
✅ Updating a Record Using Patch()
- Insert a Button (
Insert > Button
). - Set its Text property to
"Save Changes"
. - Set the OnSelect property to:
Patch(
EmployeeRecords,
Gallery1.Selected,
{
Name: txtName.Text,
Email: txtEmail.Text,
Position: txtPosition.Text
}
)
📌 Behavior: Updates the selected record with new values without using a form.
🔹 Step 8: Using RemoveIf() to Delete Multiple Records
Sometimes, you may need to delete multiple records based on a condition.
✅ Example: Delete Employees Older than 60
RemoveIf(EmployeeRecords, Age > 60)
📌 Behavior: Deletes all records where Age is greater than 60.
🔹 Step 9: Handling Errors During Edit/Delete Operations
To catch errors while updating or deleting records, use:
If(
IsError(SubmitForm(EditForm1)),
Notify("Error updating record!", NotificationType.Error),
Notify("Record updated successfully!", NotificationType.Success)
)
📌 Behavior: Displays an error notification if the update fails.
🔹 Step 10: Best Practices for Editing & Deleting Records
✅ Enable confirmation dialogs before deleting records.
✅ Use role-based permissions to restrict who can edit or delete data.
✅ Log deleted records to a backup table for recovery.
✅ Use error handling to catch and manage failures.
✅ Refresh the data source after any changes to keep records updated.
🔹 Conclusion
Editing and deleting records in Power Apps forms are essential for dynamic applications. Whether using built-in forms, the Patch() function, or RemoveIf(), Power Apps provides multiple ways to manage data efficiently.