As a Business Central developer we have from time to got used to using xrec and rec as container for previous value and current new value.
However, there are certain scenarios when xrec doesn’t work as intended.
I had a scenario where I was debugging and wanted to know where a value was changed in code. To make it easier I used the trick to do a subscriber event on the OnAfterModify trigger on that record and put a break point there to see xrec and rec and where it was changed.
Quickly I discovered that xrec and rec showed the same value. Then I remember that xrec doesn’t always work and a trick is to get the record instead with record.get to get the value before it gets written. So I changed my code and got this.

Wait, all of these are the same, even the item.get. Then it hit me… 🤦♂️ As you can see we are subscribing to the OnAFTERModify event which takes place AFTER the new value has been written to database.
Ok, then I tried the OnBeforeModify event instead and got the following result:

Here we see that the xrec doesn’t work on OnBeforeModify BUT record.get works!
I took this to twitter and AJ Kauffmann pointed out that xrec only works in your code when your are assigning a field through validate and use the event OnBeforeValidate. I tried that and it gave me the following result:

So when assigning a value with record.validate and listening to OnBeforeValidate event you get the xrec value.
Further on it was pointed out that xrec only works as intended on pages so I had to test that as well which gave the the following result:

And it is right, xrec works as intended on pages with OnAfterModifyEvent.
Conclusion
It is dangerous to use xrec if you don’t know when it actually works. As we can see xrec only works with the OnBeforeValidate event when you are assigning through validate with your own code. Otherwise it only works on pages.
For more in depth explanation of this I recommend this blog post “How to get a reliable xRec” by AJ.