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

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 …

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

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s