Table Subscriber OnAfterModifyEvent xRec vs Rec values
- AL Extension Version: 0.17.30289
- Server Version: "1.0 (Business Central Spring 2018)"
The issue that I am having is using a table subscriber event, the xRec and Rec values are showing the same for something I know specifically is being modified.
I have this table record DimSetMap. You can see from the Rec & xRec before the modify that the value is indeed changing.
The Current Value of field DimSetID=5.
It is being Set to value of 12 which is the Rec."Dimension Set ID"
Stepping into the code, I hit this Event Subscriber for the DImSetMap Record.
This is a snippet event subscriber code:
[EventSubscriber(ObjectType::Table, Database::"WSI DimSetMap", 'OnAfterModifyEvent', '', true, true)]
local procedure OnDimMgtModify(RunTrigger: Boolean; var Rec: Record "WSI DimSetMap"; var xRec: Record "WSI DimSetMap")
begin
IF Rec.DimSetID=xRec.DimSetID THEN EXIT; //No Change
IF Rec.SalesPurchase = DimMap.SalesPurchase::Sales THEN begin
It is exiting as Rec.DimSetID=xRecDimSetID.
Why are both of these the same. Rec.DimSetID should be equal to 12 (which it is) but xRec.DimSetID should be equal to 5 (But it's also 12) which is wrong.

I also tested this same scenario using "2.0 (Business Central Fall 2018)" and had the same results.
This is an issue as I can't compare the before and after values for the table in the Table OnAfterModifyEvent
Thanks,
I am encountering this issue, too. If you call the OnModify() trigger from code, the xRec and Rec are always the same. If you trigger the OnModify from the UI, the xRec gets filled correctly. Even in the onBeforeModify trigger, xRec and Rec are the same. So there is absolutely no way to get the old value when onModify is triggered from code.
I can't see any reason why it should behave that way.
Unfortunately, the behavior has always been that xRec is a snapshot of the record contents as it was when shown to the user (or rather, as it was when passed to the server). Defining the value when changed through code is hard, as the value can be modified multiple times by code, and hence there is not a consistent time where the snapshot can be taken.
We ahve experimented with changing the semantics, but every change has caused severe regressions in existing code, which assumes the current behavior
I know this is an old issue, but I think the documentation must be updated to actually reflect this behaviour.