Audit Trail

I need to create an audit trail to keep track of all the changes to all of the information in my database. Is there an easy way to do this other than checking every attribute with the retrieved one from the database, before committing it. I would like to set up some sort of generic microflow/action that can take any object and will record what are the changes. I have seen there is a change log table in the application database and i would like similar information as this but for my modeled database. So that it says the action, the object, date and who did it. Is this possible at all? I was thinking it could be possible to do it in java but i have no idea how to go about it? Any help would be great!
2 answers

What I would do is let all the objects you want to track inherit from some superobject (let's call it TrackerObject) and then add an after commit event to that object. The Microflow linked to the object should call a Java action which retrieves all the members of the object (so that you'll get all of the subobject's members) and then record them in whatever format you'd like (one option would be to create a referenceset from TrackerObject to LogObject which has a single text attribute in which you save all the different versions. Each time an object would be committed a new LogObject would be created and linked to the TrackerObject)

In the Java Action you'd have to do something like this:

        // BEGIN USER CODE
        Map<String, ? extends IMendixObjectMember<?>> members = myObject.getMendixObject().getMembers();
        StringBuilder sb = new StringBuilder();
        for (Entry<String, ? extends IMendixObjectMember<?>> m : members.entrySet())
            sb.append(m.getKey() + " : " + m.getValue());

        return sb.toString();
        // END USER CODE

Hope that gets you on your way :)


We've implemented this but used a reference to a logobject for each object that we want 'audit trailed' rather than inheritance (as objects can only inherit from one object).

For each changed attribute we create a logline with a reference to a logobject, creating changeslogs with lines to show the previous and value of each attribute. We check in a generic java action which attributes have been changed so that we don't need to bother about specifying / keeping in sync which actual attributes need to checked for changes (can't help you with the java though...)