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

Dynamics 365 CE Solution Import Failed in Azure DevOps Pipelines

Got the below error while importing Dynamics CRM Solution via Azure DevOps Pipeline. 2024-12-18T23:14:20.4630775Z ]2024-12-18T23:14:20.74...

2 days ago

PowerFx Formatting If Statement Idiosyncrasies

Disclaimer: This entire blog is an opinion, and opinions are like butts, we all have one.  This is not doctrinal truth that must be obser...

22 days ago

Power Automate – Power Fx integration with Power Automate for desktop

Get ready to experience the magic of low-code language with Power Automate for desktop! The exciting news is the integration of Power Fx scrip...

1 month ago

Generating Power Fx Formulas with Multi-Language Comment Support in Power Apps Using Copilot

The Comment-Generated Formulas feature in Power Apps lets you create Power Fx formulas directly from code comments. By typing `//` or ‘/*’ fol...

1 month ago

Executing SQL Server stored procedures with Power FX in Power Apps

A stored procedure in SQL is a pre-defined collection of SQL commands stored within the database, optimized to enhance execution efficiency an...

1 month ago

Exploring the Differences: Managed vs. Unmanaged Solutions in Dynamics CRM/Dataverse

In Dynamics CRM/Dataverse, solutions are central to Application Lifecycle Management (ALM), providing a structured way to manage, package, and...

1 month ago

Effective Strategies for Debugging Plugins in Dynamics CRM

In a recent interview, I was asked about debugging plugins in Dynamics CRM. The interviewer specifically wanted to know my approach to plugin ...

1 month ago

Power Automate: Instant Low-Code Plugins To Run PowerFx Code

Power Automate can run PowerFx code by calling an instant low-code plugin. An instant low-code ... The post Power Automate: Instant Low-Code P...

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