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

Enhancing Knowledge Retrieval with Microsoft Copilot Agents in Dynamics CRM and SharePoint

Studies show that 70% of employees spend unnecessary time searching for information across multiple systems, leading to productivity losses an...

6 days ago

Power Platform – Create and Use Power Fx Functions Public preview

We are introducing the public preview for Create and Use Power Fx Functions in Power Platform. This preview will streamline the process for cr...

7 days ago

Microsoft Releases Custom Power Fx Functions Feature for Power Automate

Today Microsoft released custom Power Fx functions to support reusable code within Power Automate. In this post how to create and use these cu...

17 days ago

{How to} become MCT Microsoft Certified Trainer on Microsoft Dynamics 365 Customer Engagement step by step instructions

Hello Everyone,Today i am going to share guidelines on becoming Microsoft Certified Trainer on Microsoft Dynamics 365 Customer Engagement or P...

29 days ago

Default Value vs. Current Value in Dynamics 365 CE: Key Differences

In Dynamics 365 CE (Customer Engagement), environment variables are used to manage configuration settings for solutions. When dealing with env...

1 month ago

How to Write and Understand a Dynamics CRM Plugin

 Here’s a sample plugin code in Dynamics CRM written in C#, along with a detailed explanation of each line. This plugin will update the "...

1 month ago

Enhancing Power Fx Formulas with Copilot in Canvas Apps

Copilot is an AI-powered feature in Power Apps Studio that streamlines the process of creating and modifying Power Fx formulas in Canvas Apps....

1 month ago

Creating Custom Data Views in Canvas Apps with Power Fx Functions

While working on a Canvas App within Power Apps, I encountered a scenario where I needed an automated calculation to handle tax computations. ...

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