Track field changes


(DBCreator) #1

I need to track whenever a specific field has its value changed. I have a project status field (StatusId) and want to log into another table the new value, user making the change and date/time the change occurred.

How would I go about it?

I know in many instances an Audit system can do this, but I only need this for 1 field, so an Audit system seems like overkill, but perhaps people here will advise me otherwise.

I thought about using AJAX within the webpage itself, but then you get into all sorts of potential exceptions and problems quickly arise which is why I’m thinking doing this through the controller makes the most sense, but, once again, perhaps people here will advise me otherwise.

Thank you for any and all advice!


(Andro) #2

Hi,

well, the AJAX request can be handled by a controller. So you can do all filtering, exception handling there.


(DBCreator) #3

I had thought about it, but how to handle false changes? Ie, the user changed the select option, thus triggering the AJAX, but then cancels out of the page. I’m then left with a tracked change that the user never committed? Is there a solution to this type of scenario?


(Andro) #4

Why triggering an AJAX request from the user then? He has committed it by his actions.
Just don’t save a tracked change then?
You can also prevent the user from leaving the page with a dialog, that his changes will be lost if he closes the tab/exits the page.


(DBCreator) #5

I ended up using the Model’s afterSave() to push, as required, to my Audit Log. Works beautifully.