Row_Inserting $rsold not accessible

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.

Sorry I didn’t explain that well, I understand rsold doesn’t exist on Add.
My issue is I can’t access rsold on Copy - it crashes?

You may enable debug and check the actual PHP error message.

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?

As the error said, the $rsold is Recordset, not array, so you may check first, e.g.

if ($rsold && property_exists($rsold, "fields")) { // Recordset
	$rsold = $rsold->fields;
}
$myValue = $rsold["MyFieldName"];

That is the answer, many thanksOn Row_Inserting $rsold is a recordset and $rsnew is an array.

	$oldstat = $rsold->fields["Status"];
	if ($oldstat=="Issued") {
             	$rsnew["Status"]="Draft";
	}

While on Row_Updated both are arrays.