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

Ticket sales management with Dynamics CRM in the Sports Industry

Mohona Dutta By Mohona Dutta | Reading time 5 mins So, how do you prospect? Pulling names out of lists on your laptop? Repeatedly calling...

18 days ago

How to create an impactful fan experience in sports with Dynamics CRM?

Mohona Dutta By Mohona Dutta | Reading time 5 mins For a salesperson, every day is game day. Sports organizations are always looking to i...

18 days ago

Updating JavaScript code in Dynamics CRM Made Easy for Developers

Hema Shamala By Hema Shamala | Reading time 5 mins Why do we need JavaScript in D365 CRM? It allows us to implement custom logic by using...

18 days ago

How To Use Advanced Find in Dynamics CRM 365

Nikhil Rajendran By Nikhil Rajendran | Reading time 5 mins One of the most commonly used features in Dynamics 365 is Advanced Find. A d...

18 days ago

Security Model of Dynamics CRM

Business Unit – It is a way to group business activities.When an organization is created, a Root Business Unit is created by default. Thi...

1 month ago

Getting Started with Power Fx in Power Pages (Preview): Low-Code Rules Made Easy

Use Power Fx in Power Pages (Preview) Power Pages is getting smarter! Until now, most of the logic you could add to forms and pages had to be ...

1 month ago

Microsoft Copilot Studio – Build enhanced connectors with the Power Platform Connector SDK and PowerFx

We are announcing the ability to create enhanced connectors for makers in Power Apps and Copilot Studio. This feature will reach general avail...

1 month ago

Run Power FX expressions through PowerApps Component Framework Events: Part 2

Introduction Just like we explored in Part 1, where Events in the PowerApps Component Framework (PCF) brought new possibilities to Model-Drive...

2 months ago

I recreated Dynamics CRM with the Power Platform Plan designer

In January 2003 after many months of engineering and development, Microsoft released one of the first business solutions built-in house; Micro...

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