Entity Change State And Getting Previous Values in SP2

I posted before about getting previous values for entity properties in SalesLogix Web. The method I used in that post made use of IEntityState to get the changes for an entity. In SP2 (version 7.2.2 – currently in release candidate as of the time of this post) IEntityState is now obsolete. It has been replaced by Sage.Platform.ChangeManagement.IChangedState. All SalesLogix entities now implement this interface.

Here’s an example of how to use the IChangedState interface to get previous values for an entity:

IChangedState state = account as IChangedState;
if (state != null)
    PropertyChange change = state.GetChangedState().FindPropertyChange("MainPhone");
    if (change != null)
        string oldValue = (string)change.OldValue;
        string newValue = (string)change.NewValue;

        // do something to compare oldValue with newValue...

I like that better. Very simple and easy to use. If you needed to check the changed state of an entity property the above won’t work. You’ll need to change it slightly to check if an entity property (from a relationship to another entity) has changed. The sample below checks if the AccountManager property on the account has changed (AccountManager is an entity property to the User entity on the Account):

IChangedState state = account as IChangedState;
if (state != null)
    EntityPropertyChange change = state.GetChangedState().FindMemberChange<EntityPropertyChange>("AccountManager");
    if (change != null && change.OldEntity != null)
        IUser oldAcctMgr = (IUser)change.OldEntity.GetReferencedEntity();
        IUser newAcctMgr = (IUser)change.NewEntity.GetReferencedEntity();

        // do something to compare the oldAcctMgr with the newAcctMgr...

Not a huge difference, but still wanted to point out that there is a difference between checking the state of standard properties vs. entity properties from relationships. For all of these samples, don’t forget to add your using directive for Sage.Platform.ChangeManagement.

One other thing to point out here. Since EntityBase (from which all entities inherit) implements System.ComponentModel.IChangeTracking, you can also use that to determine if changes have been made. See the example below which checks to see if the account’s address has changed:

// using System.ComponentModel;

IChangeTracking tracking = (IChangeTracking)account.Address;
if (tracking.IsChanged)
    // the account's address has changed.
    // do something important here...

Many ways to skin a cat – and I don’t even like cats :-p


Ryan Farley

Ryan Farley is the Director of Development for Customer FX and creator of slxdeveloper.com. He's been blogging regularly about SalesLogix, now Infor CRM, since 2001 and believes in sharing with the community. His new passion for CRM is Creatio, formerly bpm'online. He loves C#, Javascript, web development, open source, and Linux. He also loves his hobby as an amateur filmmaker.

1 Comment

  1. Norm,

    The IChangeTracking interface only defines whether an entity or object has changed. It doesn’t have anything to tell you current/previous values. For that you’d have to get those from things built into the entity itself.



Submit a Comment

Your email address will not be published. Required fields are marked *

Subscribe To Our Newsletter

Join our mailing list to receive the latest Infor CRM (Saleslogix) and Creatio (bpm'online) news and product updates!

You have Successfully Subscribed!