Tips & Tricks: who was it and when?

by Giuseppe Lanzi on 02/12/2016

In developing multi-user applications, especially those in the business sphere, it’s often necessary to be able to answer the question “who was it that changed this, and when was it done?”. It’s a subject I also deal with when consulting with people approaching Document Orientation for the first time or with people launching a new software project. Given the interest so many people have shown in this subject, I’d thought I’d write a post about it.

Once again, Document Orientation is coming to our aid, through two functionalities in particular: the use of Document Helper to globalize events, and the ability to save any document in XML format. But let’s work in order.

The first thing we need to achieve is that any document saved in the application records all of its changes somewhere. In this example project I created a logs folder in the database, where the DNA of the document, the file resulting from the conversion to XML created using the savetoXML function, the user who made the change, and the time the operation occurred will be written. This is easy to achieve. In fact, all you need to do is implement your own extension of IDDocumentHelper and implement the onGlobalAfterSave event, as in this image.

At this point, any change the application makes to any document will be recorded in the table.

The second thing to do is to ensure that the user can view the history of changes for a given document, irrespective of its type. On the product management form you’ll find a tree of the categories and products in the application. Using the tree, you’ll be taken automatically to the data editing form, and here you can save. To display the history of changes to the user, I’ve implemented a context menu command that opens a second form.

Now we come to the third item we need to address: how can we display the changes made to any document without writing specific code? Simple: using the XMLDocument object. Navigating the XML code for the document saved previously in the logs, we can see the complete status of the document at the time it was saved. This status includes both the new value of each of the properties of the document as well as the values they may have had when the document was read by the database. With an IMDB table and the lines of code below, the job is done.

What do you think? Do you have any questions? 🙂

Leave a Comment

Previous post:

Next post: