Recordref: How to sort by FieldNo instead of FieldIndex?
mr.burns
Member Posts: 39
Hello,
I create a function to copy the content of a table given by table ID to a textfile. What I do is:
My problem now is the order of the fields in the textfile is not same as the order of the fields in the table.
This is because the loop uses the fieldindex of the recordref and this goes from 1 to FIELDCOUNT.
What I need is a recordref sorted by FIELDNO as I see if I open a table using the designer.
Is there any way to loop through a recordref variable which is sorted by FieldNo instead of FieldIndex?
Thanks for any help!
I create a function to copy the content of a table given by table ID to a textfile. What I do is:
Table.OPEN(TableID); // Table is of type recordref
FieldCount := Table.FieldCount;
FOR FieldIndex := 1 TO FieldCount DO
BEGIN
// copy fieldcontent to textfile
END;
My problem now is the order of the fields in the textfile is not same as the order of the fields in the table.
This is because the loop uses the fieldindex of the recordref and this goes from 1 to FIELDCOUNT.
What I need is a recordref sorted by FIELDNO as I see if I open a table using the designer.
Is there any way to loop through a recordref variable which is sorted by FieldNo instead of FieldIndex?
Thanks for any help!
0
Comments
-
Hi
If you need the contents of the record set you could use thisOBJECT Codeunit 90005 Value to Text Using Field Ref { OBJECT-PROPERTIES { Date=03/07/07; Time=11:20:16; Modified=Yes; Version List=Toolbox; } PROPERTIES { OnRun=BEGIN TextFile.TEXTMODE := TRUE; TextFile.CREATE('C:\Temp.txt'); Field.SETFILTER(TableNo,'%1',3); IF Field.FINDSET THEN BEGIN RecordReference.OPEN(Field.TableNo); IF RecordReference.FINDSET THEN REPEAT Field.FINDFIRST; TextLine := ''; REPEAT FieldReference := RecordReference.FIELD(Field."No."); TextLine := TextLine + '|' + FORMAT(FieldReference); UNTIL Field.NEXT = 0; TextFile.WRITE(DELCHR(TextLine,'<','|')); UNTIL RecordReference.NEXT = 0; RecordReference.CLOSE; END; TextFile.CLOSE; END; } CODE { VAR Field@1000000005 : Record 2000000041; TextFile@1000000006 : File; Char@1000000003 : Char; T10@1000000004 : Text[1]; RecordReference@1000000000 : RecordRef; FieldReference@1000000001 : FieldRef; TextLine@1000000002 : Text[1024]; BEGIN END. } }
This is using the Payment Terms table and output looks like thisADVANCE|0D||0|Payable in Advance|No CHEQUE|0D||0|Cheque Payment|No COD|CD||0|Cash Payment|No DIRECT|0D||0|Direct Bank Transfer|No EOM|CM+1M||0|End of Current Month + 1 Month|No PRE|0D||0|Pre-Paid before delivery can commence|No 14DAYS|14D||0|14 Days|No 15DAYS|15D||0|15 Days|No 30 DAYS|30D||0|30 Days from Invoice Date|No 30DAYS|CM+1D+1M-1D||0|30 Days|No 30DDISC|CM+1D+1M-1D||2.5|30 Days Less 2.5% Discount|No 60DAYS|60D||0|60 Days|No 7DAYS|7D||0|7 Days From Installation|No 7DAYSS|CM+7D||0|7 Days from statement|No 7DAYS1|7D||0|7 Days From Invoice|No 7DDISC|7D||10|7 Days from Invoice less 10% Discount|No 90DAYS|90D||0|90 Days|No
or is it the field names and numbers you want if so just use the "field" table
Albert0 -
Thanks, that helped!0
-
I never noticed it was different? :?
Well, you can use the Field table, and loop throug that, and use "FldRef := RecRef.FIELD(Field."No.")" instead of "FldRef := RecRef.FIELDINDEX(FieldIndex)"
Seems I were to slow to press Submit...Regards
Peter0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.7K Microsoft Dynamics NAV
- 18.8K 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
- 328 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