Power Apps  

Patching Multiple Records at Once in Power Apps with ForAll ๐Ÿš€

Introduction

This article explains how to use ForAll inside Patch to update multiple records in Power Apps. Many apps need to change several items at once, such as updating statuses, applying user inputs, or saving data from a gallery. By combining ForAll with Patch, Power Apps can go through each record in a list and update it automatically. This lets users apply changes to many records with a single action, making the process faster, cleaner, and more efficient.

Prerequisites

Before implementing this , ensure the following:

  • A Data source such as SharePoint or Dataverse.

  • A working screen, gallery or form where the Patch action will be triggered. In my case I have used gallery.

Below is the Use Case and steps to Patch Multiple Records at Once in Power Apps with ForAll:

Use Case

Consider a scenario where we have to Manage Branding & UI Settings for Multiple Customer Portals.

A company provides customized customer portals for different departmentsโ€”such as Finance, HR, Sales, and IT. Each department's portal requires its own branding settings, including header colors, menu styles, accent colors, visibility toggles, and layout options. All these settings are stored in a SharePoint list called Sample Portal Config.

To manage these settings in Power Apps, we need to:

  • Load all settings for the selected portal

  • Show them in a gallery

  • Allow the user to change them

  • Save all updated settings back to SharePoint at once

Step 1: Set up the gallery screen

  1. Insert a Gallery control to display your settings.

  2. Inside the gallery, add:

  • Label โ†’ Set Text property:

ThisItem.Title
  • Text Input โ†’ Set Default property:

ThisItem.Value
Screenshot 2025-12-05 184718

Step2: Load settings on screen OnVisible

When the screen becomes visible, the app rebuilds PortalConfigCol.

  • It clears any existing data in the collection. This ensures there are no previous or outdated records.

  • It loops through six predefined setting names. And Setting.Value gives us each name one-by-one.

  • For each setting, it checks if a record already exists in 'Sample Portal Config' for the selected portal.

  • If a matching record exists, it adds that saved record to the collection.

  • If no record exists, it adds a new default record with an empty value.

This guarantees that PortalConfigCol always contains all six settingsโ€”either saved or newly createdโ€”ready for display and editing in the gallery.

Add below logic on OnVisible property of screen:

Clear(PortalConfigCol);
ForAll(
    [
        "HeaderBackgroundColor",
        "SidebarVisibility",
        "AccentColor",
        "FooterTextColor",
        "LayoutMode",
        "MenuColor"
    ] As Setting,
    If(
        !IsBlank(
            LookUp(
                'Sample Portal Config',
                Title = Setting.Value && PortalName = SelectedPortal
            )
        ),
        Collect(
            PortalConfigCol,
            LookUp(
                'Sample Portal Config',
                Title = Setting.Value && PortalName = SelectedPortal
            )
        ),
        Collect(
            PortalConfigCol,
            {
                Title: Setting.Value,
                Value: "",
                PortalName: SelectedPortal
            }
        )
    )
);

[Note: SelectedPortal comes from the previous screen. When navigating to this screen, we pass the portal name like this:

Navigate(Screen2, ScreenTransition.Cover, { SelectedPortal: "Finance" })

So on Screen2, SelectedPortal = "Finance", and that value is used in the LookUp to load the correct portal settings. You can pass the portal name into SelectedPortal dynamically instead of hard-coding it.]

Step3: Set gallery data source

  • Set the Items property of the gallery to:

PortalConfigCol

Step 4: Save updated configuration.

Add below logic on the Save Configuration button OnSelect property:

1) Patch updated values back to data source:

Patch(
    'Sample Portal Config',
    ForAll(
        Gallery5_1.AllItems As Item,
        {
            Title: Item.Title,
            PortalName: Item.PortalName,
            ID: Item.ID,
            Value: Item.TextInput1.Text
        }
    )
);
  • Loops through all items in the gallery (Gallery5_1)

  • Builds a table of records containing updated configuration values

  • Uses Patch() to update all items in 'Sample Portal Config'

Important Note: Here 'ID' is the primary key. It is important to use primary key as it prevents duplication record creation.

2) As previously explained: Rebuild the collection again.

Clear(PortalConfigCol);
ForAll( ...same logic as above... );

After saving, we rebuild PortalConfigCol so the screen reflects the latest saved values.

Conclusion

By following the steps above, you can efficiently update multiple records in Power Apps at once using ForAll inside Patch. This approach simplifies bulk updates, ensures all records are updated accurately, and reduces the need to write repetitive Patch functions for each item.