SETTABLE/GETTABLE - different behaviour in 2009 and 2016?

toLLto
Member Posts: 34
Hi,
we are upgrading a NAV 2009 R2 Database to 2016. There are some 3rd party objects, and some of them don't work the same way in new NAV. In 2009 I've such code:
_Rec.SETRANGE(Code, _Code);
_RecordRef.OPEN(_TableNo);
_RecordRef.SETTABLE(_Rec);
IF NOT _RecordRef.FIRST THEN EXIT(0);
_FieldRef := _RecordRef.FIELD(_FieldNo);
in 2009 both _RecordRef and _Rec have the same filters applied after this code executes. In 2016 not anymore and the _RecordRef is taking the first record from the table.
In MSDN I read that SETTABLE actually should set the table of the Record Variable as the same as RecordRef variable. This would mean that above code is completely wrong, it should use the GETTABLE function. But why it worked in 2009? Or is this somekind of a bug in 2016?
I found over 300 usages of this function in this small add-on, and now we need to decide if we need to correct all this lines and be sure that it will not brake after future 2016 CU.
we are upgrading a NAV 2009 R2 Database to 2016. There are some 3rd party objects, and some of them don't work the same way in new NAV. In 2009 I've such code:
_Rec.SETRANGE(Code, _Code);
_RecordRef.OPEN(_TableNo);
_RecordRef.SETTABLE(_Rec);
IF NOT _RecordRef.FIRST THEN EXIT(0);
_FieldRef := _RecordRef.FIELD(_FieldNo);
in 2009 both _RecordRef and _Rec have the same filters applied after this code executes. In 2016 not anymore and the _RecordRef is taking the first record from the table.
In MSDN I read that SETTABLE actually should set the table of the Record Variable as the same as RecordRef variable. This would mean that above code is completely wrong, it should use the GETTABLE function. But why it worked in 2009? Or is this somekind of a bug in 2016?
I found over 300 usages of this function in this small add-on, and now we need to decide if we need to correct all this lines and be sure that it will not brake after future 2016 CU.
0
Best Answer
-
SETTABLE copies the RecordRef instance to the record. GETTABLE copies the record instance to the RecordRef.
So the code is wrong. However, I remember there was a bug in some builds (probably 2009 something) which caused this wrong behavior.
BTW: You do not need to OPEN the RecordRef before GETTABLE.Cheers
Carsten
==> How To Ask Questions The Smart Way
This post is my own opinion and does not necessarily reflect the opinion or view of my employer.5
Answers
-
SETTABLE copies the RecordRef instance to the record. GETTABLE copies the record instance to the RecordRef.
So the code is wrong. However, I remember there was a bug in some builds (probably 2009 something) which caused this wrong behavior.
BTW: You do not need to OPEN the RecordRef before GETTABLE.Cheers
Carsten
==> How To Ask Questions The Smart Way
This post is my own opinion and does not necessarily reflect the opinion or view of my employer.5
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