databaseManager.saveData does not work in dbi events

Hi, is it possible to insert records in the database inside onRecordUpdate, onRecordInsert, and onRecordDelete events of a dbi file? I’d like to develop our own audit trailing.

the call to save data will not work no, because you are current IN save data.
But your records that you create will be saved after the “master” saveData

Hi Johan, thanks for the reply. Can you give me an example?

Why doesn’t this code work, assuming test is a valid database and table?

function onRecordInsert(record)
{
	var tempFoundset = databaseManager.getFoundSet("test","test");
	tempFoundset.newRecord();
	var tempRecord = tempFoundset.getSelectedRecord();
	databaseManager.saveData(tempRecord);
}

what doesn’t exactly work?

Is after everything is done the tempRecord not saved?
calling this line:

databaseManager.saveData(tempRecord);

doesn’t do much in a dbi event method, that call will be ignored at that time and will later be handled

How is that “record” exactly saved?

The onRecordInsert’s “record” is saved during a call to databaseManager.saveData(record).

After executing the onRecordInsert, with the “databaseManager.saveData(tempRecord)”, and the saveData(record), tempRecord is still not saved but the"record" is saved.

yes that is the sequence that doesn’t work

if you call databaseManager.saveData(record)

and that record has an oninsert event that saved again another record then that record will not be saved even if you call saveData() on it in, thats currently a limitation
(it only works for a databaseManager.saveData() so without a specific record as the start of a save)

This is because first you say you only want to save that record (and no others) and in an insert event method we block/ignore the call the another saveData() because that is kind of a recursive call for us.
There are some possibilities for that , like recording the calls to saveData(x) when a onInsert happens and make sure that those are saved, but currently servoy hasn’t that support, please make a case.

Hi Johan,

It seems that the database events are not triggered for the log table. Is that correct?

Gr. Omar

If you mean servoy logging then that is right, because that logging is purely done on the server (there are no records or something on the client for that)
We just send to the server update/insert this record then if you have enabled logging that will result in the server that another insert is created in the log table, the client doesn’t do that.
So that means no dbi event for that insert.

Ok thanks! Congratulations b.t.w. on your next post (nr. 7000)

Thx ;)

Yeah, Johan is the biggest spammer on this forum ;)

Congrats johan ! :)

I’ll make a case if needed.

Thanks Johan for all the help!

Case created: https://support.servoy.com/browse/SVY-2535

jcompagner:
yes that is the sequence that doesn’t work

if you call databaseManager.saveData(record)

and that record has an oninsert event that saved again another record then that record will not be saved even if you call saveData() on it in, thats currently a limitation
(it only works for a databaseManager.saveData() so without a specific record as the start of a save)

This is because first you say you only want to save that record (and no others) and in an insert event method we block/ignore the call the another saveData() because that is kind of a recursive call for us.
There are some possibilities for that , like recording the calls to saveData(x) when a onInsert happens and make sure that those are saved, but currently servoy hasn’t that support, please make a case.

Hi Johan,

In Erik’s example he’s trying to create and save a new record from a different table that does not have the onRecordUpdate event at all.
I understand that recursion will occur if you’re saving a record in the “test” table and inside the event create one more record in the same table and call save - that’s going back to onRecordUpdate for the same table.
But yes, if the new record is from an irrelevant table - are we still going to have trouble saving it?

Cheers,
Maria

no you are already in saveData() that calls the dpi event of that record that you want to save in the first place

and inside dbi event related method databaseManager.saveData() doesn’t do anything (at least not right away)
because dbi events methods are triggered by a previous saveData() so you are already saving data when you call saveData…

jcompagner:
no you are already in saveData() that calls the dpi event of that record that you want to save in the first place

and inside dbi event related method databaseManager.saveData() doesn’t do anything (at least not right away)
because dbi events methods are triggered by a previous saveData() so you are already saving data when you call saveData…

Ok.
Is it the same for afterRecordUpdate() ? afterRecordUpdate runs after the record was updated and saved, I suppose?

Cheers,
Maria

Yes that’s the same thing

jcompagner:
Yes that’s the same thing

Ok, thanks, Johan.

This will be fixed in Servoy 7.3 , see https://support.servoy.com/browse/SVY-1088 for more details.