Hi,
I’m using a MS SQL-DB and the logging from Servoy.
I’ve additional fields in the log-table.
Is there any way to to add a function which is called when the log-records are written?
I found that all log-records are written after leaving a record.
I created a function to populate the addtional fields.
Within that function is use: “var done = plugins.rawSQL.executeSQL(“winxam”,“log”,_query1)”
There is no EVENT “when a record is left” (opposite of onRecordSelection)
So I call my function in the very beginning of onRecordSelection() See sample below.
I there a better way to do it?
Harro
function onRecordSelection(event) {
if (globals.table_name_previous && globals.pk_previous_record ) {
// application.output("letzte Tabelle im Zugriff: "+ globals.table_name_previous+ " PK: "+globals.pk_previous_record)
databaseManager.saveData()
globals.UpdateLogTab(globals.table_name_previous,globals.pk_previous_record)
}
globals.table_name_previous = controller.getName()
/** * @type {String} */
var strpk = lngid.toString()
var lenpk = strpk.length
var strlenpk = lenpk.toString()
lenpk = lenpk.toString()
globals.pk_previous_record = strlenpk + "." + strpk + ";"
Have you looked a the table events? The afterRecordUpdate might be a nice event for it. That way you don’t have to attach a method to each form that uses the table.
I haven’t used it yet but take a look at the databaseManager.addTrackingInfo() method. It looks like this is designed for what you want to do but I’m not sure how and if it works correctly in this particular scenario.
But … log files are written from changes in 6 different Tables.
I want to update in the log-Table information from those tables in relation from the value of table_name.
My impession is that databaseManager.addTrackingInfo(‘new_field’,‘Hello’)
writes to a field a specific value. Maybe a value from variable.
I think I cannot solve my problem with that.
Perhaps you have the answer to my question in the post before.
I read all related log-records with “getDataSetByQuery”
Now I want to update the additional fields in the logtable.
I don’t know how.
The automatic log-entries by Servoy are also made outside of the eventmodel so I think there is no harm in using the rawSQL plugin here. There are so many ways to update data that it is kind of hard to tell you which one you should use. It also depends on the amount of modified records.
An efficient approach for updating multiple records is to fill a foundset with the records you want to update (databaseManager.getFoundset(…)) and then use the foundsetUpdater to loop through it and update the individual records. Like this:
var count = 0;
var fsUpdater = databaseManager.getFoundSetUpdater(foundset)
while(fsUpdater.next())
{
fsUpdater.setColumn('myColumn', myValue);
}