{dynamics crm clone record} Using Xrm.Utility.openEntityForm to clone all fields of one record to another in Dynamics CRM.

Looking at the title of the topic, you must be wondering what’s new in here. I think many of us by this time already know that we can clone one record of an entity to create another record easily using the  Xrm.Utility.openEntityForm method. For e.g suppose we have an account record and we have a functionality provided to clone the account record. The cloned record would contain the same values and the parent record.

To do this in CRM, all you need to do is the following.

var parameters = {};
parameters["name"] = "Test";
parameters["telephone1"] = "(425) 555-1234";
Xrm.Utility.openEntityForm("account", null, parameters);

Now comes the big question. Although its pretty simple to copy field values from one record to another using the above method, imagine of a situation where there are lot of fields on the form to clone. Even for that matter there can be situations where the field is not even in the form of the parent record but you would still need to copy it to the clone record. What’s the solution in that case?

Well as they say Old is Gold. Remember the _CreateFromId and _CreateFromType parameters that we used to clone a record in our early CRM 2011 days. You can use the same stuff in CRM 2013/ 2015 also. The following is the code to copy all the values from the parent account record to the cloned account record.

var accountId = Xrm.Page.data.entity.getId();

accountId = accountId.replace(‘{‘, ”).replace(‘}’, ”);

var parameters = {};

parameters["_CreateFromId"] = "{" + accountId + "}"; // Guid of the record from which values would be copied

parameters["_CreateFromType"] = "1"; // objecttypecode of the record

parameters["etc"] = "1"; // cloned entity objecttypecode

parameters["pagetype"] = "entityrecord";

Xrm.Utility.openEntityForm(Xrm.Page.data.entity.getEntityName(), null, parameters);

And voila! You are presented with a new form with all the values copied from the parent record.

Hope this helps!

Author: Debajit

I am a Dynamics CRM Most Valuable Professional (MVP) with 12 years of experience in Microsoft .NET Technologies and 9 years of dedicated experience in Microsoft Dynamics CRM. I have worked with companies like Microsoft, SanDisk, PwC, TMF Group and have extensive experience of implementing complex CRM solutions from both offshore and client side. Currently the face of XrmForYou.com with significant experience in delivering corporate training on Dynamics CRM and have already delivered multiple projects to client through XrmForYou.com Author of multiple tools on codeplex including the 'Role Based Views' and 'CRM-Sharepoint Metadata manager & Attachment Extractor' which are available for commercial use under XrmForYou.com For consulting/ training, drop me a note at info@xrmforyou.com or visit our website www.xrmforyou.com

9 thoughts on “{dynamics crm clone record} Using Xrm.Utility.openEntityForm to clone all fields of one record to another in Dynamics CRM.”

      1. I am trying to clone contact record. On a button click I am trying to call Javascript with your code.
        Here I can see parent contact Id is filling and 2 others are getting copied. No other values are getting copied to cloned records.

  1. Hi, I am trying to use this on dynamics online. When I run this code, a new form opens, but no values are getting copied over to the new form. Do I need to make adjustments to accommodate for crm online? Thanks for any help. Great post.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s