Log info when updating or delete rows in database

Log info when updating or delete rows in database

  
Hi,

I need to log info when the users change or delete some records on a table, besides old information i want to log User who change data and time of change...

I can do this by implementing trigers in database tables on update and delete events, or I can create some user action to do that, but it's not very clean, and easy to manage.

Do you have any other sugestions to do that?

Can OutSystems implent a process that alow me, when creating a table XXTABLE, decide if a tabel is for log or not.

Something like having XXTABLE and XXTABLE_LOG.

Is this some crasy idea?! :)

Thks


Hi Miguel,

> I need to log info when the users change or delete some records on a table,
> besides old information i want to log User who change data and time of change...
> I can do this by implementing trigers in database tables on update and delete
> events, or I can create some user action to do that, but it's not very clean, and easy
> to manage.

You cannot recomend you to use triggers because:
  1. you will not be able to log the userid involved in the delete or update operation;
  2. you will easily forget to update the triggers during staging / upgrades;
  3. you will probably break the createEntity methods leading to createEntity returning wrong identifiers;
  4. you will have more obscure database behavior leading to harder debugging processes.

I propose a simple pattern with one special Create and Update user action for each Entity that requires logging. You can use the "Find & Replace Usages..." menu option on your entity to help you spot the Create and Update operations that need to be replaced (in version 3.2.1 you can also find and replace each Create or Update action instead of searching for the Entity usages).

> Can OutSystems implent a process that alow me, when creating a table
> XXTABLE, decide if a tabel is for log or not. Something like having XXTABLE
> and XXTABLE_LOG.

This is a good suggestion for future releases. Can you give us more details on the pattern you use? What is the structure of your log tables?

Greetings,
Lúcio
Hi,

Right now I’ve managed that, by creating a user function that saves a msg with entity name and fields separated by ";" ,userID and currentdatetime in a table (msg(text) , userID , Datetime).

About the suggestion, I was thinking on something like this…
When a user is creating an entity on service studio, on entity options would be “create log table” as Boolean. If this option is true, in database, it would be created 2 tables, XXtable and XXtable_LOG, the second one , with the same structure as first and with 2 more fields, UserID and chagedDatetime. Also when that option is true, entity actions “delete”, “update” and “create or update” should manage information to write on both tables.

This is what I was thinking about…