How to get a reliable xRec

When events were introduced in C/AL code, one of the most discussed was the OnAfterModify event. Back in 2016, Vjeko wrote an article about it:

There are actually two problems that play a role here. The first one is that the value of xRec can’t be trusted. The variable xRec is supposed to have the original value of the variable Rec when a record is modified. However, this is only the case when the user modified the record from the UI. When a record is modified by code with Rec.Modify(), then xRec has the current value of Rec instead of the original value.

Source : Arend-Jan Kauffmann
Read more…