Updating stored calculations HELL !!!

Help,
This is driving me mad, could anyone give me a recommended way of updating calculations based on related aggregates, I have searched the forum and there seems to be differing opinions on what is the best approach,
I have tried database.recalculate, database.savedata, both these methods seem to unreliable, the only way to remedy the situation is to unstore the calculation, which is not possible.

Method for recalculating data in inventory table

var vRecordId = arguments[0] // will receive the recordId that your button method passed

controller.find()
productsid = vRecordId
controller.search(true,false)

databaseManager.recalculate(foundset); //recalculate the inventory item

globals.gStockOnOrder = value_on_order //load calculations to a global to see value
globals.gStockOnCommit = value_commited
globals.gStockOnShelf = value_on_shelf
globals.gStockOnNetShelf = net_on_shelf

databaseManager.saveData() //save data

Ok, I do not know weather this is a clue, but if the debugger is on the values are updated correctly, without the debugger no update.

With Debugger

00:00:047	3	00:00:015	Aggregate SQL	select sum(inventory_ord) as inventoryORD, sum(sub_total) as orderTotal, sum(back_order_qty) as inventoryBO, sum(inventory_in) as inventoryIN from purchase_line_items where purchase_id = ? limit ?
00:00:016	1	00:00:016	Aggregate SQL	select sum(inventory_ord) as inventoryORD, sum(sub_total) as orderTotal, sum(back_order_qty) as inventoryBO, sum(inventory_in) as inventoryIN from purchase_line_items where product_id = ? limit ?
00:00:000	1	00:00:000	Find	select productsid from inventory where productsid = ? order by productsid asc limit ?
00:00:000	1	00:00:000	Find	select productsid from inventory where productsid = ? order by productsid asc limit ?, ?
00:00:000	1	00:00:000	Update	update inventory set value_on_order=?, modified_date=?, last_reorder_quantity=? where productsid = ?
00:00:000	1	00:00:000	Update	update purchase_line_items set sub_total=?, inventory_ord=?, buy_qty=?, back_order_qty=?, modified_date=? where purchase_line_itemsid = ?
00:00:000	1	00:00:000	Update	update purchases set purchase_total_inc=?, gst_amount2=? where purchasesid = ?

No Debugger

00:00:000	1	00:00:000	Find	select productsid from inventory where productsid = ? order by productsid asc limit ?
00:00:000	1	00:00:000	Find	select productsid from inventory where productsid = ? order by productsid asc limit ?, ?
00:00:000	2	00:00:000	Aggregate SQL	select sum(inventory_ord) as inventoryORD, sum(sub_total) as orderTotal, sum(back_order_qty) as inventoryBO, sum(inventory_in) as inventoryIN from purchase_line_items where purchase_id = ? limit ?
00:00:000	1	00:00:000	Update	update inventory set modified_date=?, last_reorder_quantity=? where productsid = ?
00:00:000	1	00:00:000	Update	update purchase_line_items set sub_total=?, inventory_ord=?, buy_qty=?, back_order_qty=?, modified_date=? where purchase_line_itemsid = ?

Help Please !!, why does the debugger fix the problem??,

This is a major problem to me at the moment and I am sure there must be others with the same difficulties.

Servoy Developer
Version 3.5.6-build 519
Java version 10.0-b19 (Windows XP)

Mysql Version 5

OK,

I think I have a work around for my problem,

By using the onFocusLost event rather than onDataChange, is there a problem with using onDataChange in a table view???

var vRecordId = arguments[0] // will receive the recordId that your button method passed

controller.find()
productsid = vRecordId
controller.search(true,false)

databaseManager.recalculate(foundset); //recalculate the inventory item

globals.gStockOnOrder = value_on_order //load calculations to a global to see value
globals.gStockOnCommit = value_commited
globals.gStockOnShelf = value_on_shelf
globals.gStockOnNetShelf = net_on_shelf

databaseManager.saveData() //save data