The "Grid_Updated" server event is used with "Grid-Edit" for a table, and "Master/Detail-Edit" for a detail table.
This event will be called after updating all records. The argument of the event ($rsold and $rsnew) are array of records before and after update (retrieved from database).
For example: You can use this event to insert all the records in "Grid-Edit" mode to another table that has same structure with the current table.
To implement that example, then let's assume the original table has the same structure with the "target_table", and for simplicity, this table contains only two fields. Both "FieldOne" and "FieldTwo" is a string/varchar field type. "FieldOne" is a primary key, therefore we will get the value from the old recordset. The value in "FieldTwo" is changed in this "Grid-Edit", therefore we will get the value from the new recordset. Of course, you may enhance this example by adding another new fields.
So here is the code how you can expose the values from both $rsold and $rsnew and process them to insert to another table.
$i = 0;
foreach ($rsnew as $row_new) {
$i++;
$j = 0;
foreach ($rsold as $row_old) {
$j++;
if ($i == $j) {
ew_Execute("INSERT INTO target_table (FieldOne, FieldTwo) VALUES ('" . $row_old["FieldOne"] . "', '" . $row_new["FieldTwo"] . "')");
}
}
}
By using that code, then all the records in Grid-Edit will be inserted into "target_table".
Hopefully this will be useful for those who need the example of how to use $rsold and $rsnew in "Grid_Updated" server event.
Happy coding, everyone! :-)