rsnew of the primary key is always empty?

hi,

i’m in the function Row_Updated server script,

i used the $rsnew[“mykey”] variable instead of $rsold[“mykey”].
i know the primary key is not updatable, but is it normal that $rsnew[“mykey”] contains nothing whereas $rsold[“mykey”] is OK ?
As my others $rsnew[“not_the_key”] fields are filled, i’m wondering why the key one is empty in the rsnew…

i might miss something too, maybe you only fill the $rsnew[“xxx”] when there is a difference with the $rsold [“xxx”] ?

Best regards

Please note that when the primary key field(s) cannot be changed in that Edit page, then it means there will be no new value(s) for that field(s).

That’s why the reason why you should use $rsold object to expose the value for the fields that are not changed.

mobhar wrote:

Please note that when the primary key field(s) cannot be changed in that
Edit page, then it means there will be no new value(s) for that field(s).

That’s why the reason why you should use $rsold object to expose the value
for the fields that are not changed.


okay, copy that.

but do you fill the rwnew only when is different from rsold ?
must we always test the difference of each field to detect an update or do we only need to detect a not-empty value in rsnew ?
imagine i have 40field and need to find is there is a update…

Have a great day,
and again, thank you very much for the tips and quick reply you made here.

amiens80 wrote:

but do you fill the rwnew only when is different from rsold ?

Not always, because when a field has value in it, and it is not changed while updating the record, then the value of that field in $rsnew will always be the same with $rsold.

You may actually test this behavior from the demo project, try to put the following code in “Row_Updating” server event that belongs to the “suppliers” table:

$this->setMessage(“$rsnew for Company Name: " . $rsnew[“CompanyName”]);
$this->setMessage(”$rsold for Company Name: " . $rsold[“CompanyName”]);

After that, then try to edit one of the suppliers record, and make sure you do not change the value in CompanyName field. As you can see, the value in $rsnew of CompanyName will be the same with the value in $rsold.

amiens80 wrote:

imagine i have 40field and need to find is there is a update…

That should not be a matter. The safest way is always to get the value from $rsnew, if you are sure that field is not read only or can be changed in Edit form.

In addition, you may simply check whether a field is changed or not by using one line PHP code, for example:

$company_name_changed = ($rsnew[“CompanyName”] == $rsold[“CompanyName”]) ? “0” : “1”; // “0” = not changed, “1” = changed