1

we are planning to use the auditing feature of CRM 2011 to track who has changed which infield for a couple of entities. But what happens if you update an entity via the IOrganizationService?

For example let's say you have an addres entity in your system with City="London" and Street="Baker Street". Now in your Code you create an entity object (late bound) for this address. You set its GUID, City="London" but Street="Downing Street"! Now you call IOrganizationService.Update for this entity. Will the auditing feature be aware of that the Street has changed but the City has not? Or will he tell me that the the City was changed when in fact it wasn't?

Adam Wagner
  • 15,469
  • 7
  • 52
  • 66
Rocko
  • 13
  • 4

1 Answers1

3

the audit will pick up unchanged fields that were submitted as part of the Update message. For example, the following code will result in the audit record recording the change to the lastname attribute though submitted value is identical to the value in the database. In other word, auditing is performed on the message level and without actually comparing values with the database (which, as I understand, would be quite expensive exercise).

var connection = CrmConnection.Parse("Url=http://localhost/acme;");
var service = new OrganizationService(connection);

// create new entity
Entity e = new Entity("contact");
e["firstname"] = "Foo";
e["lastname"] = "Bar";
Guid id = service.Create(e);

// change just the first name and submit unchanged last name as well
e = new Entity("contact");
e["contactid"] = id;
e["firstname"] = "FooChanged";
e["lastname"] = "Bar";
service.Update(e);

// remove the entity
service.Delete("contact", id);

Hope this helps.
George

georged
  • 1,348
  • 2
  • 12
  • 12
  • Exactly - it is important for the client code to only submit changes. Besides unnecessary auditing, you may also unintentionally fire custom plugins if you submit fields that didn't really change. – Josh Painter Aug 05 '11 at 02:46