locked
MS CRM 2011 : Clone a record of custom entity RRS feed

  • Question

  • Hello,

    With MS CRM 2011

    I want to clone a record of custom entity using javascript function called from button in the ribbon and open automatically the newly created record.

    could someone help me?

     

    Thanks a lot.

     

     

     

     

     

    Friday, August 26, 2011 7:01 PM

Answers

  • Hello all,

     

    I do  cloning recods throught plugin and javascript.

    using Xrm Client Extensions someting like this on pre-update entity by cloning entity image:

     			Guid cloneId = Guid.Empty;
                            Entity clone = EntityExtensions.Clone(entityImage, false);
                            clone.Attributes.Remove("new_name");
                            clone.Attributes.Remove("new_dossierid");
                            clone.Id = Guid.NewGuid();
                            cloneId = service.Create(clone);
     
                            if (cloneId != Guid.Empty)
                            {
                                if (entity.Attributes.Contains("hli_clonedid"))
                                    entity.Attributes["hli_clonedid"] = cloneId.ToString();
                                else
                                    entity.Attributes.Add("hli_clonedid", cloneId.ToString());
                            }
    

     

    put the newly created clone id in the source record to open it via javascript.

     

    Thanks for all.

    • Marked as answer by w.benamor Tuesday, September 27, 2011 8:48 AM
    Tuesday, September 27, 2011 8:48 AM

All replies

  • Cloning the record itself, and not the form, isn't a very well documented thing at this stage in CRM 2011's life-cycle, it seems.  CRM 4 had lots of resources to address it.  You might be able to take some of that code and parse it through Mitch Milam's CRM Migration Assistant to get what you need.  Of course, that assumes you're looking to clone the record itself, and not the entity form.


    Dave Berry - MVP Dynamics CRM - http:\\crmentropy.blogspot.com Please follow the forum guidelines when inquiring of the dedicated CRM community for assistance.
    Sunday, August 28, 2011 9:38 AM
    Moderator
  • You can do this code-free if you want to.  From the existing custom entity's form initialize a dialog where the user inputs the new entity record's name.  Then have it run a workflow that creates a new entity record using the existing field values in addition to the new name provided by the user.
    Monday, August 29, 2011 1:04 PM
  • Hello all,

     

    I do  cloning recods throught plugin and javascript.

    using Xrm Client Extensions someting like this on pre-update entity by cloning entity image:

     			Guid cloneId = Guid.Empty;
                            Entity clone = EntityExtensions.Clone(entityImage, false);
                            clone.Attributes.Remove("new_name");
                            clone.Attributes.Remove("new_dossierid");
                            clone.Id = Guid.NewGuid();
                            cloneId = service.Create(clone);
     
                            if (cloneId != Guid.Empty)
                            {
                                if (entity.Attributes.Contains("hli_clonedid"))
                                    entity.Attributes["hli_clonedid"] = cloneId.ToString();
                                else
                                    entity.Attributes.Add("hli_clonedid", cloneId.ToString());
                            }
    

     

    put the newly created clone id in the source record to open it via javascript.

     

    Thanks for all.

    • Marked as answer by w.benamor Tuesday, September 27, 2011 8:48 AM
    Tuesday, September 27, 2011 8:48 AM
  • how to clone sub grid record?

    Awen

    Tuesday, October 21, 2014 12:47 AM