Import dataport and skipping the header line

kriki
Member, Moderator Posts: 9,121
Problem:you have a textfile with headers and you must import it with a dataport, but you want to skip the header line, because otherwise you get an error. How to do that?
Put some code in trigger "OnPreDataItem()":
(variable "cha" is CHAR)
Put some code in trigger "OnPreDataItem()":
(variable "cha" is CHAR)
IF CurrDataport.IMPORT THEN BEGIN REPEAT CurrFile.READ(cha); UNTIL cha = 10; // of course in case the RecordSeparator is "<<NewLine>>" END;
Regards,Alain Krikilion
No PM,please use the forum. || May the <SOLVED>-attribute be in your title!
No PM,please use the forum. || May the <SOLVED>-attribute be in your title!
1
Comments
-
And for more than 1 line:
IF CurrDataport.IMPORT THEN BEGIN LintLinesToRead := 2; // lines that must be read (this is an integer) REPEAT CurrFile.READ(cha); IF cha = 10 THEN LintLinesToRead -= 1; UNTIL LintLinesToRead = 0; END;
Regards,Alain Krikilion
No PM,please use the forum. || May the <SOLVED>-attribute be in your title!1 -
I get an error "File is not open" at Currfile.Read(cha) part of the code.
i dont want to hardocode the filepath but when the "user" slects the "csv"file from the options tab
iam using 4.0(SP3)
ThanksRegards,
GD0 -
are you sure the code is on PreDataItem not PreDataPort?
(variable "cha" is TYPE CHAR)0 -
thanks savatage #-oRegards,
GD0 -
I am missing the logic for the Until cha = 10;
Is 10 the expected number of records?Experience is what you get when you hoped to get money0 -
No, the 10 is the ASCII value of the line feed.
A newline in a textfile is defined by 2 chars : CR/LF = Carriage Return + Line Feed = ASCII 13 + ASCII 10.
So I am reading char per char until I find ASCII value = 10. When I have found it, I know I am at the end-of-line.Regards,Alain Krikilion
No PM,please use the forum. || May the <SOLVED>-attribute be in your title!0 -
Thanks, it is a long time since I had to think about ASCII.
I have used your code and it works perfectly, many thanks.Experience is what you get when you hoped to get money0 -
Simple and Brilliant.
Thanks. :thumbsup:David Singleton0 -
Worked like a charm! Thank you!
\:D/Marcelo Borges
D365 Business Central Solutions Architect
BC AL/NAV C/AL Developer
BC Repositories.com0 -
Perfect! Thanks.0
-
I like it when I see that an old reply is still useful to fix problems.Regards,Alain Krikilion
No PM,please use the forum. || May the <SOLVED>-attribute be in your title!0 -
It works for me, thank you so much.Thanks & Regards,
Muthu0
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