How to update multiple records in a model-driven app grid using Power Fx commanding
If you wanted to add a button to a command bar to perform an update on multiple records in a grid, you can easily create a formula that results in slow performance caused by multiple grid refreshes. This post outlines, the most performant way of applying updates to multiple records from a Power Fx command button.
Step 1 - Add your button
Inside the modern command bar editor, add a button to the Main Grid or Sub Grid command bars of the Account entity.
Step 2 - Set the Visibility rule
Any buttons on a grid that apply to selected records will only become visible if you provide a visibility rule.
Select the Visibility property, and select Show on condition from formula.

In the formula bar at the top, enter the following:
!IsEmpty(Self.Selected.AllItems)
Step 3 - Add the command formula
Select the Action of the button, and select Run formula.

In the formula bar at the top, enter the following:
// Paralle Updates
Patch(
Accounts,
ForAll(Self.Selected.AllItems,
{
Account:ThisRecord.Account,
'Credit Hold':'Credit Hold (Accounts)'.Yes
}
)
)
Note: If you are adding a button for a different entity, you will need to change the table name (Accounts) and primary key column name (Account).
Step 4 - Save and Publish, then Play your app!
The changes will take a short while to appear in your app. You will see a message similar to the following when the changes are ready:

Parallel vs Sequential Patches
If you used the following formula, it would result in multiple grid refreshes since the Patches will be done in sequence.
// Sequential Updates
ForAll(Self.Selected.AllItems,
Patch(
Accounts,
ThisRecord,
{ 'Credit Hold':'Credit Hold (Accounts)'.No }
)
);
Using the parallel version above instead of this sequential one will try and perform as many parallel updates as the browser can handle. This is due to the limited number of HTTP requests that can be sent simultaneously from the browser.
You can see in the timeline below, that only 6 parallel requests are in progress at once.

Despite this, this technique will be considerably more efficient than performing the updates sequentially, and the grid will only be refreshed the once, instead of with each record updated.
Published on:
Learn moreRelated posts
Azure Data Factory Tips for Reliable Microsoft Dynamics 365 CE and Dataverse Integrations
Reliable integrations between Microsoft Dynamics 365 Customer Engagement and external systems can become challenging. This is especially true ...
Power Platform Fundamentals #4: Understanding Power Fx in Power Apps: Core Functions, Formula Patterns, and Real-Time Business Scenarios: Quick Read Series
1. Business Scenario In modern enterprise applications, business logic is deeply embedded across user interfaces and data processes. This incl...
Dynamics 365 CE: Known Issues Creating Word Templates
A classic feature worth revisiting, today’s focus is Word Templates in Dynamics 365 CE/CRM. This tool remains a powerful option available for ...
Exploring Type and RecordOf functions in Power Fx
In Dynamics 365, when working with Power Apps inside the Dynamics 365 ecosystem, especially when consuming Dataverse APIs or Power Automate re...
Adding Native Confirmation Dialogs with Power Fx function
Before the built-in Confirm() function existed, adding a simple yes/no confirmation in Power Apps required significant manual effort. In canva...
Architecting Scalable Business Logic in Dynamics CRM Using Plugin Life Cycle
Dynamics CRM Plugin Life Cycle: Optimizing for Scalability means designing plugins in a way that keeps the system fast, stable, and easy to ma...
Avoiding Currency Mismatch Errors in Dynamics 365 CE
When working with Dynamics 365 Sales, it’s important to understand how currency behaves across related entities like Opportunity, Quote, Order...
Sales Collaboration: How Sales Teams Work in Dynamics 365 CE
A Sales Team in Microsoft Dynamics 365 Sales represents a group of users who collaborate to manage and close sales opportunities efficiently. ...