Loading...

How to update multiple records in a model-driven app grid using Power Fx commanding

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 more
Develop 1 - Dynamics 365 Architecture Services
Develop 1 - Dynamics 365 Architecture Services

Share post:

Related posts

What Are Power Fx Functions And How Do They Work With Power Apps?

When you build an app in Microsoft Power Apps, the screen layout is only the visible part. The real behavior of the app depends on the logic b...

6 days ago

AI Agents in Microsoft Power Platform: Where Custom Agentic CRM Fits in Dynamics 365 Customer Engagement

In many CRM planning conversations right now, AI agent discussions are starting before organizations have fully aligned governance, integratio...

14 days ago

Business Process Flows in Dynamics 365 CE

Let’s look back at an oldie but a goodie in Dynamics 365 CE/CRM: Business Process Flows! These are designed to standardize how records m...

15 days ago

20 Most Commonly Used JavaScript Scenarios with Sample Code Snippets in Form Script – Dataverse / Dynamics 365 CE

JavaScript plays a critical role in Microsoft Dataverse and Dynamics 365 Customer Engagement (CE) applications. While Power Automate and Busin...

21 days ago

Dynamics 365 CE and Power Platform Developer Syllabus

Extensive & Advanced Syllabus for Power Platform & Dynamics 365 CE If you want to become an expert in Microsoft Power Platform and Dyn...

21 days ago

From Campaign Automation to Agentic Marketing: The Next Phase of Microsoft Dynamics 365 Customer Engagement

As organizations evaluate Microsoft Dynamics 365 Customer Insights capabilities, a common question keeps emerging: Are we still designing camp...

28 days ago

Dynamics 365 CE 2026 Release Wave 1 Launch Event Webinar

Western Computer recently hosted a launch event walking through Dynamics 365 CE 2026 Release Wave 1, focused on what's changing across Sales, ...

1 month ago

Power Fx: User Defined Types Generally Available

User Defined Types (UDTs) are now generally available! As of Power Apps Studio version 3.26044, UDTs are enabled by default for new apps and c...

1 month ago

Microsoft Copilot in Dynamics 365 Customer Engagement: Where Teams See the Most Value

Artificial intelligence, particularly Microsoft Copilot in Dynamics 365 Customer Engagement, is quickly becoming part of everyday work across ...

1 month ago
Stay up to date with latest Microsoft Dynamics 365 and Power Platform news!
* Yes, I agree to the privacy policy