This is an Archived topic. The solution is available in the Thinkstore inside the Software Factory.
Goal
The goal of this solution is to automatically add trace fields to all tables so the user can see who added the record or who made the last change. This solution adds these fields to a separate tab page on a form. This looks like this in the GUI:
You can choose at what moment you want the fields to be filled: During editing or after saving the record.
Solution
The solution consists of code for Dynamic Model (for adding the fields) and two Control Procedures (for filling the fields). Depending on the moment you want the fields to be filled (during editing or after saving), you can choose either for a control procedure for defaults or for a control procedure for triggers.
Dynamic model add_trace_columns
This code adds trace columns to every table.
The trace fields are:
-
update_user
-
update_date_time
-
insert_user
-
insert_date_time
If you add the tag 'no_trace' to a table, no trace columns will be added to that table. The trace column are automatically translated in ENG and NL.
Important: Make sure that the Generation order has a low number, e.g. 10. The columns must be generated before the generation of the program objects.
The code in this topic is created in the Software Factory 2020.2.
Control procedure default_fill_trace_columns
This control procedure fills the trace column with the current user and date through defaults.
Template default_fill_trace_columns
This template fills the trace column with the current user and date.
Control procedure trigger_fill_trace_columns
This control procedure fills the trace column with the current user and date by the trigger. Insert triggers and update triggers have different templates.
Template trigger_fill_trace_columns_insert
This template fills the trace columns with the current user and date after an insert.
Template trigger_fill_trace_columns_update
This template fills the update trace columns with the current user and date after an update. If the update trigger is nested in another trigger, the trace columns will not be updated.
In the attachment you will find the code of this solution.