How to use $rsold and $rsnew in Grid_Updated server event

Tips submitted by PHPMaker users

How to use $rsold and $rsnew in Grid_Updated server event

Postby mobhar » Tue Nov 14, 2017 9:45 pm

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) {
$j = 0;
foreach ($rsold as $row_old) {
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! :-)
Posts: 4661
Joined: Wed Jun 05, 2013 2:11 pm

Re: How to use $rsold and $rsnew in Grid_Updated server even

Postby anil » Fri Nov 24, 2017 8:36 pm

Well...Working fine
Posts: 13
Joined: Mon Aug 14, 2017 12:27 pm

Re: How to use $rsold and $rsnew in Grid_Updated server even

Postby rocarona » Fri Dec 01, 2017 11:49 am

thanks for the tips.

regarding master/detail setup, is it possible to automatically update field value as a result from calculation between 2 other field on master table which one of them is total sum from detail table?

for example:

id (int)
jams (varchar)
nilai (decimal)
cicilan (decimal) <===== total sum from
sisa (decimal) <==== should be 'nilai' - 'cicilan'

id (int)
item (varchar)
qty (double)
cicilan (decimal)
total (decimal) <===== should be 'qty' - 'cicilan'

Thanks for your help...
Posts: 1
Joined: Thu Jun 16, 2016 12:42 am

Re: How to use $rsold and $rsnew in Grid_Updated server even

Postby kirondedshem » Fri Dec 01, 2017 1:19 pm

to get a value as a result of calculating from detail and put it into master table in master/detail add/edit form,
phpmaker has no automated way around this yet So
the way I currently do it is using jquery where I can find all detail elements, get thier values and sum them up the put result into a filed in master form. I put this logic in a fnction which I can call onchange from any field I want
You can look at these two topics to get an idea on how to:

"Total of checked items (Selected Items) from list" on viewtopic.php?f=4&t=40703
"Total Qty" placement under detail table on viewtopic.php?f=4&t=40925

Just look at the implimentation and change it to your own or make your own similar approach
Posts: 315
Joined: Sat Jan 28, 2017 7:13 pm

Return to User Submitted Tips (PHPMaker)