Dataport import and output error in a txt file
peterro
Member Posts: 9
Dear all,
I am using dataport to import data into Navsion table Location from a text file .
My text file contain some errors ( text lenght exceed or illegal caracter etc ).
Does anyone know is there any way to validate the data during import? How can import data and skip the errors and write error to a text file.
Your comment is highly appriciated.
Regards,
I am using dataport to import data into Navsion table Location from a text file .
My text file contain some errors ( text lenght exceed or illegal caracter etc ).
Does anyone know is there any way to validate the data during import? How can import data and skip the errors and write error to a text file.
Your comment is highly appriciated.
Regards,
0
Comments
-
Instead of using the field in the dataport, use a global variable.
This you can test in the "OnAfterImportRecord()"-trigger.
If it is not ok, you can skip the record (=CurrDataport.SKIP;).
For writing to a file, you have to open it in the "OnPreDataItem()"-trigger and close it in the "OnPostDataItem()"-trigger.Regards,Alain Krikilion
No PM,please use the forum. || May the <SOLVED>-attribute be in your title!0 -
kriki wrote:Instead of using the field in the dataport, use a global variable.
This you can test in the "OnAfterImportRecord()"-trigger.
If it is not ok, you can skip the record (=CurrDataport.SKIP;).
For writing to a file, you have to open it in the "OnPreDataItem()"-trigger and close it in the "OnPostDataItem()"-trigger.
I'm beginner .... if you post some example code ?
I'm disperate .... pls help me
thanks0 -
OnPreDataItem()
intRecord := 1; filFile.WRITEMODE(TRUE); filFile.TEXTMODE(TRUE); filFile.QUERYREPLACE(TRUE); filFile.CREATE("The File Name");
OnAfterImportRecord()intRecord += 1; IF STRLEN(txtImportedText) > MAXSTRLEN("Some Field In The Table" THEN filFile.WRITE('The text for "txtImportedText" is too big for record' + FORMAT(intRecord)); // this IF STRLEN ... MAXSTRLEN.... you have to write for each field in the dataport that can be too long // txtImportedText is a text or a code with a length that is long enough to contain all chars
OnPostDataItem()filFile.CLOSE;
I didn't test the code, but this is less-or-more what you will need.Regards,Alain Krikilion
No PM,please use the forum. || May the <SOLVED>-attribute be in your title!0 -
Any solution guys ?
here is my example of my import :import.txt
I have one table with 2 fields : code and location
<|333156|>^<|DEPOZIT BULK|> ./ldjwzz/....
<|333953|>^<|K-MAG PLOIESTI 1|>
<|333954|>^<|K-MAG TARGOVISTE 1|>
<|334033|>^<|K-MAG GIURGIU 1|>}}[e
<|334148|>^<|MARFA NEEXPEDIATA|>
<|334149|>^<|MARFA NERECEPTIONATA|>
<|334204|>^<|K-MAG GALATI 1|>
<|334205|>^<|K-MAG GALATI 2|>----87362,,mdjd
how to set up a dataport to skip this records and output error filed to a text file ?0 -
I came up with this code, but I only chech the first line of the imput text file. How can I go to the next line ?
fisier.TEXTMODE(TRUE); fisier.CREATE('C:\Erori.TXT'); intrare.TEXTMODE(TRUE); intrare.OPEN('c:\mmm.txt'); intrare.READ(rand); start := 1; pozitia := STRPOS(rand, '^'); // fisier.WRITE(pozitia); WHILE (( (pozitia > 0) AND (pozitia < STRLEN(rand)-4) ) AND (intrare.POS<STRLEN(rand)-4) ) DO BEGIN sirul := COPYSTR(rand, start, pozitia-1); // fisier.WRITE(sirul); IF ( (STRPOS(sirul, '<|') <> 1) OR (STRPOS(sirul, '|>') <> STRLEN(sirul)-2) ) THEN BEGIN fisier.WRITE(rand); CurrDataport.SKIP; END; pos := pozitia; start := pozitia + 1; sirul := COPYSTR(rand, start, STRLEN(rand)); pozitia := STRPOS(sirul, '^') + pos; END; sirul := COPYSTR(rand, pozitia + 1, STRLEN(rand)); IF sirul <> '' THEN BEGIN fisier.WRITE(rand); CurrDataport.SKIP; END;0 -
Lets do this step-by-step.
First make a dataport with 1 field (a text (=txtTheInputText) of 1024) [at least if your textfile doesn't contain lines longer than 1024 characters].
This will read the file line by line.
You can check it if you put a MESSAGE('%1',txtTheInputText); in the OnAfterImportRecord()-trigger.
So you don't need to do a read from a file. This is handled by the dataport. Look at the standard-import dataports. In general there is no code for importing. The DataItem you can use, is the "Integer"-table with properties "AutoSave","AutoUpdate","AutoReplace" = No.
Once this works fine, you can start putting your code to test the input and to write errors to the textfile:
In the OnPreDataItem()-trigger you open the textfile for writing.
In the OnAfterImportRecord()-trigger you text the textline and write errors to the textfile.
In the OnPostDataItem()-trigger you close your textfile.Regards,Alain Krikilion
No PM,please use the forum. || May the <SOLVED>-attribute be in your title!0
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
- 323 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