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!
Discover more from Debajit's Power Apps & Dynamics 365 Blog
Subscribe to get the latest posts sent to your email.
Reblogged this on Nishant Rana's Weblog.
When I tried the same example, I can see existing Parent Account is filling in New record. But not all values are copying from parent record. Any issue ?
Hi Arun,
Sorry for the late reply since i was travelling.
Can you let me know what type of variables are not getting copied?
Regards
Debajit
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.
Pingback: Debajit's Dynamics CRM Blog
Is there a way to use this to copy fields from Account to another Entity using the Xrm.Utility.openEntityForm()?
Hi,
I haven’t tried this..let me try this over this weekend and get back to you.
regards
Debajit
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.
Hi fishyjj,
Sorry for the delayed reply as I was on vacation. This post was written with Dynamics CRM 2013 and it used to work with it. However it seems not to work with the 2016 version. You can however use the below link – https://dipankarbhattacharya.com/2014/02/19/cloning-a-record-in-dynamics-crm-2013/ which would work in CRM 2016 as well