Tracking changes in related SalesLogix entities
Posted By: nicocrm on January 19th, 2011 in Saleslogix
No Gravatar

I have been doing a bit of exploration via trial and error and wanted to post my findings here. Note all of those were found on SLX 7.5.2.

Say you want to audit changes in an entity related to the main entity of your form… for example in my case ticket.Contact (the customer can edit the contact’s first name from the ticket screen), or this would probably work the same with the address control on the account main view. You may run in the following issues:

  • If you don’t make any change to the main entity itself, its Update event will not get called.
  • The Update event of the related entity will not get called
  • When you try to retrieve the changes for the related entity, you can’t simply do “((IChangedState)ticket.Contact).GetChangedState()” – this will return an empty change set. Instead you have to go through the member changes of the main entity.

Not much can be done about the first 2 items unfortunately – the event is just not getting triggered. This means you have to call the method to track the changes from the application code unfortunately for the time being (hopefully it will get fixed soon since it creates a pretty big hole in sdata applications – I have not tested to see if it was on 7.5.3). In the meantime let me elaborate on the last point. The main entity (e.g. ticket) keeps tracks of changes to related entities in its own ChangeSet. To retrieve changes on one of those linked entity you can use the Find() method of the ChangeSet to retrieve an EntityChange object. For some reason it does not allow one to retrieve this EntityChange using the property name (such as what you might use for FindPropertyChange or FindMemberChange ), but since you already know the id and it will be unique you can just use something like

EntityChange customerChange = changes.Find(x =>
          (String)x.ChangedEntity.EntityId == (String)ticket.Contact.Id);
if (customerChange == null)

From there, retrieve a ChangeSet using customerChange.ChangedEntity.EntityChanges, and you can manipulate that one like a regular ChangeSet:

ChangeSet changes = customerChange.ChangedEntity.EntityChanges;
PropertyChange nameChange = changes.FindPropertyChange("FirstName");

For a more deeply linked entity like ticket.Contact.Address it is also retrieved from the ticket entity’s ChangeSet:

EntityChange addressChange = changes.Find(x =>
    (String)x.ChangedEntity.EntityId == (String)ticket.Contact.Address.Id);

Hope this helps!

Leave a Reply