[Model-driven apps – Power Fx] How to open multiple rows in new tabs using Power Fx commands ?

Mehdi El AmriDyn365CE2 years ago23 Views

According to the roadmap published by Microsoft, Power Fx commands for model-driven apps will go into general availability from May 2022. This blog will discuss an example using modern commands, and I hope it will encourage you to adopt this new way to customize the command bar and buttons.

As mentioned in the blog title, let’s see how it is possible to create a new button that will open multiple records in different tabs. Before going further, keep in mind that classically realizing this functionality requires JavaScript code.

Demo:

How does it work?

Button creation is done on the app designer. You can find all the details about the creation of a new button on the following documentation. Without going into detail about the steps to follow to create the button. We will focus on the business rules that the button must respect:

  • The button should be visible on the main grid for the account table.
  • The button should be visible if and only if a row is selected in the grid
  • When clicking on the button, the selected rows will be opened in new tabs

So that the button is visible in the main grid. This option must be selected when opening the command designer :

The button visibility can be managed with Power Fx. The rule corresponds to the following formula :

CountRows(Self.Selected.AllItems) > 0

Now, to open the records in a new tab. Then, to open the records in a new tab, the following Power Fx action can be used :

ForAll(Self.Selected.AllItems,Launch("/main.aspx?pagetype=entityrecord&etn=account&id="&ThisRecord.Account))

Let’s try to understand this formula. In fact, the command executes the Launch() function for all the selected rows. Indeed, the Launch() function allows opening a web page by passing it a URL address. The most interesting thing is that the function also supports relative URLs !!

For example, to open an account record form for where the id is  {91330924-802A-4B0D-A900-34FD9D790829}. The following url can be used:
https://myorg.crm.dynamics.com/main.aspx?etn=account&pagetype=entityrecord&id=%7B91330924-802A-4B0D-A900-34FD9D790829%7D

The corresponding relative URL is:
/main.aspx?etn=account&pagetype=entityrecord&id=%7B91330924-802A-4B0D-A900-34FD9D790829%7D

Now back to the Power Fx formula. To get the GUID of the selected account. The following formula is used: ThisRecord.Account. The relative URL is as follows:

/main.aspx?pagetype=entityrecord&etn=account&id="&ThisRecord.Account

With this approach, relative URLs can be used with the Launch function to open forms, views or reports in a new tab. To learn more about the various possibilities, this documentation will be helpful.

Hope it helps …

Original Post https://xrmtricks.com/2022/04/10/model-driven-apps-power-fx-how-to-open-multiple-rows-in-new-tabs-using-power-fx-commands/

0 Votes: 0 Upvotes, 0 Downvotes (0 Points)

Leave a reply

Join Us
  • X Network2.1K
  • LinkedIn3.8k
  • Bluesky0.5K
Support The Site
Events
March 2025
MTWTFSS
      1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31       
« Feb   Apr »
Follow
Sign In/Sign Up Sidebar Search
Popular Now
Loading

Signing-in 3 seconds...

Signing-up 3 seconds...