8

I'm using CRM 2011, and attempting to update the OwnerId of contact using this code:

var crmContext = new CustomCrmContext(service);

var contact = crmContext.Contact.FirstOrDefault(c=>c.Id == id);
contact.OwnerId.Id= newOwnerId;
crmContext.UpdateObject(contact);
crmContext.SaveChanges();

I don't get any errors, however, the ownerId never updates in the database. I am able to update other attributes, but I'm just wondering if maybe the OwnerId is special and you have to use OrganizationRequest("Assign")? If so, where is this documented so I know what other attributes I cannot update?

Daryl
  • 18,592
  • 9
  • 78
  • 145

1 Answers1

12

The owner of a record cannot be modified with an update. You have to send a AssignRequest instead.

// Create the Request Object and Set the Request Object's Properties
var request = new AssignRequest
{
    Assignee = new EntityReference(SystemUser.EntityLogicalName, _newOwnerId),
    Target = new EntityReference(Account.EntityLogicalName,  _accountId)
};


// Execute the Request
_service.Execute(request);
ccellar
  • 10,326
  • 2
  • 38
  • 56
  • Is there a list of other properties that require a specific request object, or is owner the only one? – Daryl Oct 13 '11 at 11:51
  • 1
    The status is another one - I think the CRM generates two classes per entity with the pattern SetStateAccountRequest and SetStateAccountResponse. – glosrob Oct 14 '11 at 17:52
  • 1
    As usual, no warning from the SDK when this fails. – Ryan Jan 04 '13 at 03:07
  • @Ryan it is simply filtered out because the owner is not an *updateable* field – ccellar Jan 08 '13 at 08:27