Access xRec-Data via RecRef?

Thalon
Member Posts: 10
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
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
-
Hi Thalon,
There is no built-in xRecRef in NAV, but you could try to use GETTABLE function together with xRec:RecRef.GETTABLE(Rec); xRecRef.GETTABLE(xRec); //xRecRef here is just a simple RecRef variable FieldRef := RecRef.FIELD(YOUR_FIELD_NO); xFieldRef := xRecRef.FIELD(YOUR_FIELD_NO); IF FieldRef.VALUE <> xFieldRef.VALUE THEN...
1 -
Hi Addo,
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,
Thalon0 -
Hi 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 codeOnModify=VAR xRecRef@1100118001 : RecordRef; RecRef@1100118000 : RecordRef; BEGIN RecRef.GETTABLE(Rec); xRecRef.GETTABLE(xRec); MESSAGE('Old %1\New %2',xRecRef.FIELD(2).VALUE,RecRef.FIELD(2).VALUE); END;
I created a record with Description 'Old', then changed it to 'New'. Here's the output of the MessageMicrosoft Dynamics NAV
Old Old
New New
OK1 -
@vaprog
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:LOCAL PROCEDURE GetModifiedFields@1100017008(); VAR Field@1100017003 : Record 2000000041; xRecRef@1100017001 : RecordRef; RecRef@1100017005 : RecordRef; BEGIN RecRef.GETTABLE(Rec); xRecRef.GETTABLE(xRec); Field.RESET; Field.SETRANGE(TableNo,RecRef.NUMBER); Field.FINDSET(FALSE,FALSE); REPEAT IF RecRef.FIELD(Field."No.").VALUE <> xRecRef.FIELD(Field."No.").VALUE THEN MESSAGE('%1\%2\\%3\%4','xRecRef:',xRecRef.FIELD(Field."No.").VALUE,'RecRef:',RecRef.FIELD(Field."No.").VALUE); UNTIL Field.NEXT = 0; END;
Thank you!
Thalon0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions