Foundset with calculation doesn't save

When I insert a row from a table A, this table have an event OnRecordInsert. This method jump and insert a row in another table B who has stored calculation from an aggregation of table A.
At the event AfterRecordInsert in the table A have:

databaseManager.recalculate(the record from the A table)
databaseManager.saveData()
databaseManager.recalculate(the record from the A table)
databaseManager.saveData()

When you do that the first time works well but the second time not. When I say that it works well is that the calculation stored from the table B is store in the data base.

All the time I am checking the data base.
And with the debug I check the record who have to be stored and is perfect, I can see the correct value at the calculation stored, but when pass the saveData it didn’t stored at the data base.
The most strange think is when you close the program it store.

You can see at the example:
It compose with 3 table (order_tbl, order_tbl_dtl, tax), and a process create_tax() who is in onRecordInsert and onRecordUpdate, and in the method afterRecordInsert and afterRecordUpdate I save the record.

To see the problem,
-inset a row in order_tbl save it,
-insert a row in order_tbl_dtl an write the order_tbl_id (put the number of the one who you save it before), price, tax, and unit. Save it
-insert another row from the same table change put a different tax from before

You have to check the table tax at the data Base.
I need that this row have to be stored because it depend on another table.

Probably I need to use a different function to refresh the record to the data base, but I ignore it.

example.servoy (9.83 KB)

Hello,

I’m curious to know what version of Servoy you are using, and with what database?

servoy 5.2.4
Data Base postgres 8.4

calling saveData() in one of the table events methods doesn’t do anything
Because there are fail saves in them so that it can’t end up in a recursion.
Thats why it doesn’t get saved. You see if you just change a value and you click somewhere on the form.
You will notice that the E in the status bar (thats says you are editing records) will not go away
you have to click again

This is because the first times saves your record, but that creates changes in other records that will then be saved on the next click.

I will see if i can fix this so that you only have to do this:

function afterInsertRecord(record) {
forms.tax_lst.controller.loadRecords(record.tax_id)
databaseManager.recalculate(forms.tax_lst.foundset)
}

(i deleted 3 lines of code)

by the way accessing forms and doing loadRecords or newRecord through the controller is something that you really shouldn’t do in data level events/methods…

Thanks jcompagner,
I didn’t know that I cannot use a saveData() on table event.
Now I understand why didn’t work.
I will prove it.

Thanks

we have found a fix for this for the next release (5.2.5)

then when saveData() is called (clicking in the ui of through code,not table events that will not work)
and when that returns true so that everything is saved, also the records that are created or updated in the afterX events will be saved.