Change Tracking on Entity Records

By Ricardo Sousa on 7 Feb 2013
Entity Record change Tracking is a very common requirement by the clients so it will be great to have it by default in the platform.

J.8 Feb 2013
How do you want it to be?

My hesitation lies in the fact that the tracking will be based on user, but many app will not use the user-entity for several reasons.
(most likely because they already have another user provider)
Furthermore do you want have some info inside the entity itself (CreatedBy, LastUpdatedBy)
How do you propose which entities are tracked and which are not?
Ricardo Sousa20 Mar 2013
Hi!

I had to do it for a project I'm working on and I did it the following way:

Created a table called Log with:

Id - Default Primary Key
Entity - Static Entity - Values: All entity names. For each Entity in my e-Space I created an record in this Static Entity
ForeignerKey - Integer - Place to save the Id of the changed entry. It breaks the type safety but it's the only* way to make it possible
ChangeType - Static Entity - Possible Values: "Created" , "Attribute Changed", etc
UserId - UserId - UserId from Session
Message - Text - Area where we can have more details about the entry. For example: "The attribute <A> changed from <Z> to <Y>"
TimeStamp - Datetime

Then I created, for each Entity, an action called CreateUpdateAndLog<EntityX> where I check if any of the attributes changed and, if so, add an entry to Log.

"My hesitation lies in the fact that the tracking will be based on user, but many app will not use the user-entity for several reasons."
 
But they need to have an UserId in Session, don't they?
 
"Furthermore do you want have some info inside the entity itself (CreatedBy, LastUpdatedBy)"

You can still save these information in the Entity if you need them very often.
 
"How do you propose which entities are tracked and which are not?"

It could be an Entity's property called "Log Changes", like the "Is Active".

Best regards,
Ricardo