
If you or someone in your role has to create the same kind of records manually multiple times, you may have already hated doing it. So, I came up with something to solve this problem.
For example, if you are a salesperson who has to create orders with almost the same data every time, with only minimal changes, you still need to create a new record from scratch. You may have wished there was a Clone option available. So, I developed a cloning functionality using a command button and Power Fx.
I have already posted a blog on cloning a record in a Model-Driven App using a command button and JavaScript. If you want to clone a record using JavaScript, you can refer to my blog on Clone a record in Dynamics 365 CE using JavaScript.
However, there is another way to achieve this. Yes, we can use Power Fx instead of JavaScript to clone a record. Without much complexity, this can be done easily using Power Fx.
As a demonstration, I created a command button named Clone Account on the Account form. In the action, select Run Formula and click Open Formula Bar. Once the formula bar opens, use the Power Fx code below, then save and publish it.
// Clone Account record without related records
If(
// show confirm dialog to clone the cloned record.
Confirm(
"Are you sure you want to Clone this record?",
{
Title: "Clone Confirmation",
Subtitle: "This action can't be undone.",
ConfirmButton: "Yes",
CancelButton: "No"
}
),
// show progress notification
Notify(
"Cloning record...",
NotificationType.Information,
3000
);
With(
{
ClonedAccount:Patch(
Accounts,
Defaults(Accounts),
{
'Account Name': "Copy - " & Self.Selected.Item.'Account Name',
'Main Phone': Self.Selected.Item.'Main Phone',
Website:Self.Selected.Item.Website,
'Address 1':Self.Selected.Item.'Address 1',
Email:Self.Selected.Item.Email,
Fax:Self.Selected.Item.Fax
}
)
},
// success message after cloning
Notify(
"Record cloned successfully.",
NotificationType.Success,
5000
);
//show confirm dialog to open the cloned record.
If(
Confirm(
"Are you sure you want to open Cloned record?",
{
Title: "Open confirmation",
ConfirmButton: "Yes",
CancelButton: "No"
}
),
// navigate to cloned account
Navigate(ClonedAccount);
);
),
// if cloning failed, show error
Notify(
"Clone operation cancelled.",
NotificationType.Error,
2000
)
)

Join the conversation! Your thoughts help the community grow.