Good morning from Gran Canaria.
I´ve been searching on the Servoy wiki about Servoy Database Events and I have not found anything.
Please anyone could guide me in the using of this events. The big question is:
I want to create methods for my orders_lines table so when the user creates, updates or delete any record some data in other tables be updated, like articles stocks, etc.
I see that wee have 2 events for each action (onEvent and afterEvent) easy to understand that one is before the data is written and the other after it has been written on the table, but how can I know the old data in both types of events?
thanks in advance.
in the onUpdate (so before) you get a record object as parameter,
on this record object you can ask for getChangedData() this will give you changed columns with old and new data.
Hi Juan,
If you create the Table Events methods through the Table Editor by double clicking the (empty) methodName fields next to the field that says “onRecordInsert” for example, the method that gets created contains JSDoc and also is created with the correct function parameters, telling you which values you get to work with.
Note that documentation for TableEvents and all the column properties will be added to the Wiki in the next iteration of documentation.
Paul
Thnaks for your reply Johan.
jcompagner:
in the onUpdate (so before) you get a record object as parameter,
on this record object you can ask for getChangedData() this will give you changed columns with old and new data.
Yes, I found that yesterday night, but getChangedData returns an array with the fields changed in a format that I understand not very easy to play with. It only returns the field that have been changed but in all the examples I´ve seen you have to reference them by a row, not by the name of the field. Is there a way to reference the old data by the field name?
Thanks.
no you just have to loop over the dataset and read out the rows column:
column1 is the column name,
colum2 is the old data and
column3 is the new data.