Editing and Deleting Records in a Form

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 TypePurpose
Edit FormAllows users to modify existing records.
New FormEnables users to create a new record.
View FormDisplays 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

  1. Open Power Apps Studio and create a new app or edit an existing one.
  2. Click on Insert > Forms > Edit Form.
  3. Position the form on the screen.

โœ… Step 2: Connect the Form to a Data Source

  1. Select the form and go to the Properties Panel.
  2. Under Data Source, select a data source (e.g., SharePoint, SQL, Excel, Dataverse).
  3. 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:

  1. Insert a Gallery control (Insert > Gallery > Vertical).
  2. Set the Items property to:
EmployeeRecords
  1. 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

  1. Insert a Button (Insert > Button).
  2. Set its Text property to "Update Record".
  3. 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

  1. Insert a Button (Insert > Button).
  2. Set its Text property to "Delete Record".
  3. 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()

  1. Insert a Button (Insert > Button).
  2. Set its Text property to "Save Changes".
  3. 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.


Leave a Reply

Your email address will not be published. Required fields are marked *