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.
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:
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/