Automatic attribute difference detection in your records

Automatic attribute difference detection in your records

Hi there everyone,

Have you ever had the requirement to be able to detect if two records of the same entity are different? Different here means that they have different values for their attributes. This feature can be necessary, for example, if you want to keep track of the changes that occurred in an entity over time.

A classical example would be to record all changes on the User entity, keeping an history of what was changed and when. If a given user changed his email from '' to '', you'd have a record of that change. This is crucial if you intend to achieve some kind of traceability, which is a requirement for almost every enterprise application.

A normal approach to this would be to hard-code this into your application code, by writing several If statements that test the different attributes. This technique has several problems, the first one being that it's incredibly boring! Here you are, using an advanced application development platform that helps you solve your business problems, and all the sudden you need to repeat code again and again. A different, albeit as problematic side effect of this technique is that it isn't built-to-change - if you forget to update your code the next time you add an attribute to your entity, it doesn't get tracked in your history of changes.

Enter Integration Studio - the tool that allows unlimited extension for the Platform. One thing that people tend to forget is that you can pretty much extend the Platform to do anything, given the right amount of coding and patience. Granted, it's not as fast as visually developing, and it sure isn't easy, but it can be done. In this specific case, we'd like to create a component that can be used to automate the hard work for you. Picture a simple Extension that can compute the differences for you, given any two records. That would save you some time, wouldn't it?

But wait... can such an extension exist? To create it, we'd need to know ahead of time every possible Entity that it could compute the differences for - or would we? In fact, we don't. We can use a .Net feature called Reflection that allows us to find out stuff about our objects without knowing their types. I'll leave the low-level details for another time, and right now you can find and attachment with a prototype for this extension (You thought this post was only chit-chat?).

To use it, just supply your two records to the DiffEntities action, wrapped in a ToObject() call. This means using ToObject(EditRecord.Record). This action returns three parameters :
  • A boolean named Changed , which indicates if the objects are different
  • a string named ChangeString, which stores a textual representation of the differences (e.g. attribute A changed from value1 to value 2)
  • a Record List with another view over the differences, using a structure that has the attribute name, original and changed values
You can use it with any record, regardless of it being composed by entities or structures (or a mix of both). What you still need is some kind of way to persist these changes somewhere, but I'll leave that one up to you and your specific details ;)

So go ahead and start keeping track of your changes in a better way - you deserve it!

Thanks for reading all the way. I appreciate any feedback you might have on this!
Hi Gonçalo,

great contribution, thanks! :)

Just a suggestion: in order to make this extension even more "multi-language" friendly, perhaps two optional input parameters could be added, "change_msg_1" and "change_msg_2", to allow the following change line template: <change_msg_1> + <value 1> + <change_msg_2> + <value 2>.

Of course, I say "even more" since you can already have this behaviour building up the change message from the returned RL... but this way it would be an added "sugar" to it ;)

Thanks again, I'll be using it often for sure.

Thanks for the heads up. That is definitely a good point.

This extension has been very helpful to us, thank you!  Do you happen to have an OS 5.0 compatible version available?  (We had difficulties trying to import it into a sandbox OS 5.0 server).  Thank you!
Hi Eric,

Have you seen these

Tiago Simões