Search code examples
c#dynamics-crmmicrosoft-dynamics

Update only some fields in a Microsoft Dynamics entity


I'm developing a software in C# language that interacts with Microsoft Dynamics through calls to Organization service.

I need to update only some fields of the entity, but when I call the Update operation, Microsoft Dynamics launches a massive update of all the fields of the entity. I don't want this massive update, I need to update only 2 or 3 fields.

This is my code:

//reading account
Entity account = <reading entity with a call to organizationService>
//update fields
account["fieldName1"] = newValue;
account["fieldName2"] = newValue2;
//call to update entity
organizationService.Update(account);

How I can solve this problem?


Solution

  • We use early binding here and we also accept the entire object will be updated, but from memory: try this

    var accountToBeSentToDynamics = new Entity("account");
    accountToBeSentToDynamics.Id = accountToBeUpdated.Id;
    accountToBeSentToDynamics["name"] = "Only This Field will be updated";
    

    We also add these to a list of inserts or updates and flush them in batches of size 1000 or less to speed performance