button on grid retrieves old data from fields

I followed the tutorial to process several records on a grid with a button in the toolbar. And I got it working just fine for starters.

But I encountered the following problem: I use a column to do some calculations in the onRecord event of the grid. More specific I calculate a fault score evaluating the data. The fault score is initially 0 (or ‘N’) and can change in the onRecord event of the grid. When I display this field in the grid the correct (calculated) value is displayed.
The button I created is to archive several records at a time. But when the fault score is >0 (or ‘Y’) then the archiving may not happen.

I tested several things out but I think that in the onRecord event of the Button itself the old value of the field (so in fact the initial value) is used in stead of the calculated value. Therefor I can not test in the onFinish event of the button if the data was faulty because it always says it was not (0 or ‘N’) …

I also discovered that the field has to be a field created by the SQL of the grid. Otherwise you get an error when pressing the button … So I guess the onRecord event of the button is executed BEFORE the onRecord event of the grid itself and therefor it stores the wrong data …

Has anybody encountered this also?

I guess I can solve this with doing a bunch of updates (even in the database before querying the data in the grid) but I am curious if anybody has another solution …


I use a toggle. I also consistently use 0/1 instead of Y/N

if ({private} == 1) {
$new_state = 0 ;
} else {
$new_state = 1 ;