Hello!
I wonder if it is somehow possible to access the data from a xRec by RecordRef?
To explain the background:
I'm working on an Export to an external system and I have to check if relevant fields have changed.
As I don't want to add code to each OnValidate-Trigger or do 50 "if Description <> xRec.Description" I'm looking for a more elegant solution, like accessing the fields via RecRef.
But I do not find a possibility to achieve this.
I'm open to suggestions (or a "not possible").
Thanks!
Thalon
0
Answers
There is no built-in xRecRef in NAV, but you could try to use GETTABLE function together with xRec:
thanks for trying, but when used in the OnModify-Trigger this returns the new entry for xRec, too.
Gettable does no "Transferfields", instead it checks the database and here the new value is returned :-(
Lg,
Thalon
your problem is probably not xRec, but Rec. In the OnModify trigger, the record has not yet been written to the database, so (assuming your explanation concerning GETTABLE is correct) xRecRef.GETTABLE(Rec) should give you access to xRec. But you are not able to get a RecRef with Rec's values.
I suggest to do it the way Change Log Management (CU 1 / CU 423) does. There, NAV provides the RecRef to Rec as parameter to OnDatabaseModify (CU 1).
Addendum
Since I doubted Thalon's claim that RecRef.GETTABLE fetches values from the database, I made a quick test:
I created a table with two fields, Code (ID 1) and Description (ID 2). Then I added the following code I created a record with Description 'Old', then changed it to 'New'. Here's the output of the Message This test has been done on NAV 2013 R2, but I don't think the version matters in this regard.
Thanks for testing.
I'm not exactly sure why my test failed, but your code works for me in NAV 2015.
Edit:
To get only the changed fields I wrote this function:
Thank you!
Thalon