I am trying to override a status field when copying a record.
The following simple code in Row_Inserting causes an error when Copying that I can’t trap
// Row Inserting event
function Row_Inserting($rsold, &$rsnew)
{
// Enter your code here
// To cancel, set return value to false
if ($rsold["Status"]=="Issued") {
$rsnew["Status"]="Draft";
}
Log("Old Status " . $rsold["Status"]);
Log("New Status " . $rsnew["Status"]);
return true;
}
If I add a new record, it is saved and log is:[2022-07-26T00:23:58.080070+00:00] log.DEBUG: Old Status
[2022-07-26T00:23:58.080336+00:00] log.DEBUG: New Status Draft If I Copy and save a record I get
Error
An internal error has occurred while processing your request.and no logs or console messages. Using V2022.12Any thoughts?
The $rsold only exists when you copy a record, when you insert a new record, there is no old record, so in your code you should check if ($rsold) first.
Enable Debug did display error detail/opt/bitnami/apache/htdocs/models/Invoices.php(2568): Cannot use object of type PHPMaker2022\stables\Recordset as arrayI don’t understand, because I can operate on $rsnew on Row_inserting e.g
public function rowInserting($rsold, &$rsnew)
{
$rsnew["Status"]="Draft";
Log("New Status " . $rsnew["Status"]);
return true;
}
I can also operate on both $rsold and $rsnew in Row_Updated functionI just can’t operate on $rsold in Row_Inserting when copying a record?