clone account gives sql server error in mscrm 2013 RRS feed

  • General discussion

  • Dear all ;

    i am trying to clone an account record through the following code but it gives sql server error

     Entity acc = service.Retrieve(entity.LogicalName, entity.Id, new ColumnSet(true));
      Entity Account = new Entity("account");
                        acc.Id = Guid.NewGuid();
                        Account = acc;
                        Account["name"] = "Cloned"+ " " + acc.Attributes["name"];
    Wednesday, February 19, 2014 8:58 AM

All replies

  • What is the SQL error you are getting?

    I suspect that the issue is that you are not clearing the CreatedOn/ModifiedOn/CreatedBy/ModifedBy fields that cannot be set on create (and other system fields).

    Try removing the system fields from the Account attributes.

    Hope this helps,


    Scott Durow
    Blog www.develop1.net    Follow Me
    If this post answers your question, please click "Mark As Answer" on the post and "Mark as Helpful"

    Wednesday, February 19, 2014 9:26 AM
  • To elaborate on Scott's answer, not all attributes are ValidForCreate (such as ModifiedOn). You can use one of two approaches to get around this:

    1. Only clone certain fields. In this case, set the ColumnSet on the Retrieve to a given set of fields
    2. Read the CRM metadata to determine which attributes have VaildForCreate = false, and remove them from the entity instance

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

    Wednesday, February 19, 2014 9:32 PM