locked
Generic SQL Error when cloning contacts RRS feed

  • Question

  • Hi everyone,

    I am trying to clone a contact entity from a Pre-image. My problem is that the creation of the new contact fails with a generic SQL error. I checked the entity metadata, and removed all the attributes which are not valid for create. However, my code still fails on the creation of the contact.

    Any ideas what could I possibly do wrong?

    My code is the following:

    Entity oldContact = context.PreEntityImages["Target"];
                    oldContact.Attributes.Remove("accountid");
                    oldContact.Attributes.Remove("aging30");
                    oldContact.Attributes.Remove("aging30_base");
                    oldContact.Attributes.Remove("aging60");
                    oldContact.Attributes.Remove("aging60_base");
                    oldContact.Attributes.Remove("aging90");
                    oldContact.Attributes.Remove("aging90_base");
                    oldContact.Attributes.Remove("annualincome_base");
                    oldContact.Attributes.Remove("contactid");
                    oldContact.Attributes.Remove("createdby");
                    oldContact.Attributes.Remove("createdon");
                    oldContact.Attributes.Remove("createdonbehalfby");
                    oldContact.Attributes.Remove("creditlimit_base");
                    oldContact.Attributes.Remove("exchangerate");
                    oldContact.Attributes.Remove("fullname");
                    oldContact.Attributes.Remove("isautocreate");
                    oldContact.Attributes.Remove("isprivate");
                    oldContact.Attributes.Remove("lastusedincampaign");
                    oldContact.Attributes.Remove("masterid");
                    oldContact.Attributes.Remove("merged");
                    oldContact.Attributes.Remove("modifiedby");
                    oldContact.Attributes.Remove("modifiedon");
                    oldContact.Attributes.Remove("modifiedonbehalfby");
                    oldContact.Attributes.Remove("owningbusinessunit");
                    oldContact.Attributes.Remove("owningteam");
                    oldContact.Attributes.Remove("owninguser");
                    oldContact.Attributes.Remove("parentcontactid");
                    oldContact.Attributes.Remove("statecode");
                    oldContact.Attributes.Remove("versionnumber");
                    oldContact.Attributes.Remove("yomifullname");
    
                    oldContact.Id = Guid.NewGuid();                          
                    Guid oldId = _service.Create(oldContact);
    

    Regards,

    Adam

    Sunday, July 7, 2013 3:50 PM

All replies

  • I am away from a development system but just try removing the line with Guid.NewGuid() and perhaps remove the Id attribute as you have the others. Think the ID is create d by the service_Create call.


    Paul Developer of Summary Plus for Dynamics CRM. http://www.clew-consulting.com/summaryplus Simple grids rolling up data from multiple levels.

    Sunday, July 7, 2013 8:48 PM
  • If you have CRM OnPremise, enable tracing to get more information on the error. My guess it's due to SQL locking

    One possibility is there may be locking on the email-related tables, so try removing the email attributes.

    One solution could be to create the lead in an asynchronous step


    Microsoft CRM MVP - http://mscrmuk.blogspot.com/ http://www.excitation.co.uk


    Monday, July 8, 2013 7:51 AM
    Moderator
  • Hi,

    Refer this post.

    HTH


    If you find this post helpful then please "Vote as Helpful" and "Mark As Answer". Thanks and Regards, Mohammad Yusuf Ansari http://microxrm.blogspot.in

    Monday, July 8, 2013 9:33 AM