Record Cloning with Command Bar control using Formula FX code in Model Driven App

 Record Cloning with Command Bar control using Formula FX code in Model Driven App

Last year, the power platform wave release introduced the Formula FX availability in the Model-driven app command Bar where we can add or customize the command properties with JavaScript & Formula FX.


1.1 Model Driven App Command bar

Command bar can be customized on Main Grid, Main Form, Sub-grid View, and Associated view where a rich set of controls can be added such as Command (button), dropdown, and split button.

1.2 Command bar controls

This article will look at how to clone records with Formula FX code by clicking on the button control in the command bar to provide business users with a nice user experience.

 

1.      Edit the Model model-driven app and choose the table where you want to customize the command bar, here you can see I choose the Account table and on click of three dots, it will show edit option to customize the Command bar.

1.2 Edit Command bar option

2.      On Click of + New you will see Command (Button), Dropdown, and Split Button, here I chose Command and dragged it onto the command bar

3.     Here you can see I have set command properties Label, icon, and in Action I chose Run Formula so that I could get access to the Formula FX code     


  4.       Now let’s see how to create a clone record, on the top formula FX code panel where you can write the code

 

·       Create Clone record:  Here we need to use the Patch() function and as it's a new record so in the Patch() function first parameter is the Table Name and the second parameter is the default() function where I have provided the account table to create new account record and in third parameter where table column data mapping must be done.

Formula FX code:  Patch(Accounts, Defaults(Accounts),{ 'Account Name': Self.Selected.name & "--Clone--"});


·     Confirm dialog box: Just to make sure it’s a correct record to be cloned.

 Confirm("Do you want to clone Record ? " & Self.Selected.name);

·       To redirect cloned record in the new browser: tab here I use the Launch() function provided the record URL which has App ID and record ID, to retrieve the latest created record ID from the Dataverse table I used the Lookup() function on the account table.

Launch("https://powerpractice.crm.dynamics.com/main.aspx?appid=391feb92-5f5c-ee11-be6f-000d3a8c698c&forceUCI=1&pagetype=entityrecord&etn=account&id=" & LookUp(Accounts, 'Account Name' = Self.Selected.name & "--Clone--").Account)



Here You can see the Final output below the screenshot 





 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Comments