Clone a record in Dynamics 365 CE using JavaScript

Fellas! Have you ever been in a situation where you needed to create multiple similar records with some fields carrying the same data? I found myself in this exact scenario and thought—why not build a simple templating functionality?

Imagine opening a new record with all the existing data prefilled, making only the necessary tweaks, and saving it — without the hassle of manually copying everything. While searching for existing solutions, I came across workflows and plugins, but they automatically save the record, which wasn’t what I needed.

I wanted something minimalistic, user-friendly, and efficient, so I explored a JavaScript-based approach.

To bring this functionality to life, I outlined the key steps required:

  • Develop the Web Resource
  • Create a Command Button
  • Demonstrate the Functionality

Develop the Web Resource

Since we are implementing this functionality on the client-side, we need to write JavaScript to handle the cloning process. The script should cover the following key actions:

  1. Retrieve the Current Record – Fetch the data of the record to be cloned.
  2. Show a Confirmation Popup – Ask the user whether they want to proceed with cloning.
  3. Open a New Form with Prefilled Values – Load a new record form with the copied data, allowing the user to make necessary changes before saving.

Below is the JavaScript code I used to achieve this functionality.

Create a Command Button

To enable the cloning functionality, we need an event trigger. The best way to do this is by adding a button on the Main Form of the respective entity. In my case, I used the Account entity and added a command button on the Main Form. This allows users to quickly create similar accounts without manually entering every field.

Steps to Add the Command Button:

  1. Navigate to the required App in the Maker Portal.
  2. Click on the three-dot menu (...) next to Accounts View.
  3. Select Edit Command Bar.
  4. Choose Main Form.
  5. In the Command Editor, click + New → Command and place it anywhere in the ribbon.
  6. Configure the command by adding:
    • Action (Run JavaScript)
    • Library (add Web Resource)
    • Function (to trigger cloning)
    • Parameter (set as Primary Control)
  7. Click Save and Publish to apply the changes.

Below is a snapshot of the configured button for reference.

Demonstrate the Functionality

After publishing, ensure that the button appears as expected. Below is a clip demonstrating the record cloning functionality in action.

Reference

Conclusion

Cloning records in Dynamics 365 CRM using JavaScript is a powerful way to improve efficiency while maintaining data integrity. With minor modifications, this approach can be customized for different entities and business requirements.

Have a great day!

Tamilarasu Arunachalam

Post a Comment

Previous Post Next Post