Tutorials/Power Apps/Add Custom Duplicate Buttons with Power Fx in Model-Driven Apps
Power Appsintermediate

Add Custom Duplicate Buttons with Power Fx in Model-Driven Apps

Learn how to extend forms and grids with a duplicate command using only Power Fx — no JavaScript needed.

NA
Narmer Abader
@narmer · Published June 3, 2026

Model-driven apps have always allowed makers to customize the command bar, but that used to require JavaScript and the Ribbon Workbench. The modern command designer now accepts Power Fx — the same language used in canvas apps — so almost anyone can add custom buttons without writing a line of JavaScript. This article walks through a real-world scenario: adding a Duplicate button to both a form and a grid view using only Power Fx.

The IT Asset Scenario

Contoso’s IT team manages thousands of assets. When a new laptop arrives, it’s often identical to an existing one except for the serial number. Instead of filling out a form from scratch, they want a single click that copies all fields from the current record. The same logic applies to the grid view when multiple similar assets need to be duplicated.

The Dataverse table is called Asset and has these columns:

Column NameData TypeExample Values
AssetNameText"Dell Latitude 5520"
CategoryChoiceLaptop, Monitor, Keyboard, Mouse, Headset
SerialNumberTextSN-LAT-2024-001
PurchasePriceCurrency1200.00

After creating the table and adding a few sample rows, you can build a model-driven app that includes the Asset table with its main form and grid view.

Setting Up the Command Designer

  1. In your model-driven app, navigate to the table Asset.
  2. Click the (more commands) next to the table name, then choose Edit command bar.
  3. You will see two contexts: Main form and Main Grid. We’ll start with the form.

Adding a Duplicate Button to a Form

In the command designer for the Main form:

  • Select New command from the left menu.
  • Set the Label to “Duplicate”.
  • Change the Icon to “Copy” (the standard copy icon).
  • Click Open Formula Bar on the right side.

Now paste the following Power Fx formula. It uses Patch with Defaults(Assets) to create a new record and maps each field from the currently displayed record (Self.Selected.Item).

powerfxDuplicate the current form record
Patch(
  Assets,
  Defaults(Assets),
  {
      AssetName: Self.Selected.Item.AssetName,
      Category: Self.Selected.Item.Category,
      SerialNumber: Self.Selected.Item.SerialNumber,
      PurchasePrice: Self.Selected.Item.PurchasePrice
  }
)
Key point

Defaults(Assets) returns an empty record for the Asset table. It ensures Patch creates a new record instead of updating the existing one.

After saving and publishing the command bar, play the app. Open any asset record, click the Duplicate button, and a new record is created with the same values. The app navigates to the new record’s form automatically.

Adding a Duplicate Button to a Grid View

Return to the command designer and select Main Grid for the Asset table. Create a new command with the same label and icon.

In the formula bar, we need to iterate over all selected rows. Self.Selected.AllItems returns a collection of the selected records. The ForAll function loops through them and Patch creates a copy for each.

powerfxDuplicate multiple selected grid rows
ForAll(
  Self.Selected.AllItems As AssetRecord,
  Patch(
      Assets,
      Defaults(Assets),
      {
          AssetName: AssetRecord.AssetName,
          Category: AssetRecord.Category,
          SerialNumber: AssetRecord.SerialNumber,
          PurchasePrice: AssetRecord.PurchasePrice
      }
  )
)

Controlling When the Button Appears

A grid command should only be visible when at least one row is selected. Set the Visible property of the command to:

powerfxVisibility condition
!IsEmpty(Self.Selected.AllItems)

Publish the command bar. In the grid view, the Duplicate button now appears only after you select one or more rows. It duplicates every selected asset.

Security and Permissions

The custom command runs with the permissions of the signed-in user. To use the Duplicate button, the user must have Write privileges on the Asset table. If the environment has multiple security roles, make sure the command is not hidden by a role-based visibility formula (you can add a condition under Show on condition from formula if needed).

Important

Because the command performs a Patch operation on the server, delegation is not a concern — but ForAll over Self.Selected.AllItems processes records in memory. Very large selections (hundreds of rows) may be slow. Keep selections reasonable.

Common Mistakes and Troubleshooting

SymptomLikely CauseSolution
Button does not appear on the formCommand not published or visibility condition too restrictivePublish again; check that Visible returns true for the form context
Formula returns an errorMisspelled field name or wrong table name in DefaultsVerify column logical names in the formula match those in Dataverse
Only one record is duplicated in gridUsing Self.Selected.Item instead of ForAllReplace with the ForAll pattern shown above
New record is created but data is blankDefaults(Assets) was omittedAdd Defaults(Assets) as the second argument of Patch

Final Recommendation

The modern command bar designer with Power Fx is a major step forward for low‑code customization. For simple operations like record duplication, it replaces the complexity of the Ribbon Workbench entirely. If your logic grows beyond a few Patch calls, consider moving it to a Power Automate flow or a custom page, but for most command bar scenarios Power Fx is more than sufficient.

References