Method 1: Manually maintain log: –
To do this we have to create a log table which will store all the data changes.
We can have fields like table_name, pk_value_of_the_record, field_name, old_value, new_value, modified_by_user_idx,modification_date, etc..
For this Servoy has some table level events like
onRecordInsert
onRecordUpdate
onRecordDelete
To keep track of the updates, create a global method and attach it to the “onRecordUpdate” event of the table.
This method automatically takes a parameter “record” of type JSRecord.
In the method we can retrieve all the field values by the following code.
function checkUpdateRecord(record)
{
var table_name = record.foundset.getDataSource().split('/')[2];
var pk_value_of_the_record = record.getPKs()[0]; //When multi select is not done
var modified_by_user_idx = //User index of the currently logged in user
var modification_date = application.getServerTimeStamp();
var dataset = record.getChangedData();//it will return all the changed data of type JSDataSet
//Loop through the modified fields
for( var cnt = 1 ; cnt <= dataset.getMaxRowIndex() ; cnt++ )
{
field_name = dataset.getValue(cnt, 1);
old_value = dataset.getValue(cnt, 2);
new_value = dataset.getValue(cnt, 3);
//Create new record in the log table and store all this values in the respective fields.
}
}
Attach this method to all the table’s onRecordUpdate event for which you want to keep update log.
Method 2: Use Servoys inbuild log mechanism: –
– For this create a server named “log_server”.
– In the admin page select “Database Servers” link.
– Tick the “Log Server” check box in the server information area of the server “log_server”.
– This information will be written in the Servoy properties file as:
servoy.log_server = “your_server”
– Restart your Servoy application Server.
– Go to any table for which you want to keep log and select “Security” tab.
– On the “Table Settings” there is a check box called “Tracking”.
– By default the tracking is disabled for all the tables.
– Tick Tracking check box of all the tables for which you want Servoy to keep Tracking.
If you want to keep the backup of the entire record, then create a duplicate table.
Use the onRecordUpdate event to store the entire old record with the modification information to the new table.
Finally use the log informations with different filtering criteria to show the History or log.