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
Debunking: Dynamics CRM Destination – How Text Lookup Works
When we want to push data to Dataverse/Dynamics CRM using SSIS – KingswaySoft, usually there are relationships (lookup) that we need to ...
Understanding Activity Party Types in Dynamics 365 CE
Dynamics 365 Customer Engagement features 11 unique activity party types, identified by specific integer values in the ActivityParty.Participa...
Debunking: KingswaySoft Dynamics CRM Source- Output Timezone
Hi! I’m back after so a long hiatus (probably I’ll write the reason for this later 🤣). As [lazy] Developers, we’re most lik...
How to configure donotreply email using Shared mailboxes in Dynamics 365 CE?
This article explains how to create and configure a Shared Mailbox in Microsoft 365 for sending emails to users in Dynamics 365 CE. It details...
Use PowerFX in Power Automate Desktop Flow
Step-by-Step Guide for Using Power Fx in Power Pages (Preview)
In this blog, we’ll explore how to use Power Fx within Power Pages to build dynamic, interactive web applications. We’ll walk through key feat...