Importing Files with Navision Application Server

CtrlShiftF11
Member Posts: 29
I am working on a project developing automated text file importing using the Navision Application Server. Because you cannot use dataports with the NAS, I have written codeunits to handle the task of importing, parsing and creating records with my delimited text files.
Right now I'm trying to use a global variable with a data type of Variant to read the file data into...
Is there a better way to do this? I'm sure that someone else has tried to use the NAS to automate regular imports.
Thanks in advance!
CtrlShiftF11 ](*,)
Right now I'm trying to use a global variable with a data type of Variant to read the file data into...
REPEAT CLEAR(ImportBuffer); CatalogImportFile.READ(ImportBuffer); //Call file handling functions to work with the ImportBuffer global here //Insert Records here, etc. UNTIL CatalogImportFile.POS = ImportFileLen;
Is there a better way to do this? I'm sure that someone else has tried to use the NAS to automate regular imports.
Thanks in advance!
CtrlShiftF11 ](*,)
0
Answers
-
I always use this, pretty much the same code
File1.TEXTMODE := TRUE; File1.OPEN('C:\Temp\Textfile); Counter := 1; WHILE File1.READ(Value) <> 0 DO BEGIN Counter += 1; Table.field1 := Copystr(value,1,10); Table.field2 := Copystr(value,20,20); Table.insert; END; File1.CLOSE;
This works fine for me and is a lot faster than a dataport when importing large amounts of data0 -
Well that's fine and all but I don't need help with the parsing and handling of the data (if you recall my data is delimited so COPYSTR with hard coded integer values wouldn't cut it for my data). You have to loop through the string and search for declared constants that serve as Text Qualifiers and Column Delimiters - which I've coded functions for.
I should have been more specific, my real question is...
In TEXTMODE should I be reading each line of the file data into a data type of VARIANT?
[-X
Thanks,
CtrlShiftF110 -
Well, you should have been more specific then.
No, you can just use a text variable, just make it a big one.
What is the delimiter you are using?0 -
I fixed it and was able to use the VARIANT data type, which gives me more than 250 characters. I originally tried to use the new BIGTEXT data type but I ran into issues. BLOBs usually don't play nice so no big shock there.
Anyway, I've about got this perfected so I'll post the source code when I'm done testing and refining in case some other poor fool runs into this very issue.
\:D/0 -
-
The following is the code that I've used to import data into Navision via a Codeunit...
OnRun() ImportFilename := 'C:\Temp\NAVItemImport_Catalog.txt'; ColDelimiter := '|'; TextQualifier := '^'; CatalogImportFile.TEXTMODE(TRUE); CatalogImportFile.OPEN(ImportFilename); ImportFileLen := CatalogImportFile.LEN; REPEAT CLEAR(ImportBuffer); CatalogImportFile.READ(ImportBuffer); FirstChar := COPYSTR(ImportBuffer,1,1); IF FirstChar = TextQualifier THEN FirstParsingPoint := 2 ELSE FirstParsingPoint := 1; ItemNo := ParseFileRecForColVal(FirstParsingPoint); IF NOT Item.GET(ItemNo) THEN BEGIN ItemDesc := ParseFileRecForColVal(FindNextParsePoint()); UPC := ParseFileRecForColVal(FindNextParsePoint()); TypeCode := ParseFileRecForColVal(FindNextParsePoint()); WITH Item DO BEGIN INIT; "No." := ItemNo; VALIDATE(Description,COPYSTR(ItemDesc,1,30)); "Long Description" := ItemDesc; VALIDATE("Item Category Code",'FG'); "Last Date Modified" := TODAY; AppFrmCommonLib.CreateDefaultItemUOM(ItemNo,'PIECES'); VALIDATE("Base Unit of Measure",'PIECES'); INSERT(TRUE); END; END; ClearImportVars(); UNTIL CatalogImportFile.POS = ImportFileLen; CatalogImportFile.CLOSE; ParseFileRecForColVal(StartingPoint : Integer) ColumnVal : Text[250] CharCounterL := StartingPoint; WHILE (CurrentCharL <> TextQualifier) AND (CurrentCharL <> ColDelimiter) DO BEGIN CurrentCharL := COPYSTR(ImportBuffer,CharCounterL,1); CharCounterL += 1; END; IF CurrentCharL = TextQualifier THEN CopyLenL := CharCounterL - (StartingPoint + 1) ELSE CopyLenL := CharCounterL - 1; ColumnVal := COPYSTR(ImportBuffer,StartingPoint,CopyLenL); LastParsingPoint := CharCounterL; EXIT(ColumnVal); FindNextParsePoint() NextParsePoint : Integer CharCounterL := LastParsingPoint; CurrentCharL := COPYSTR(ImportBuffer,CharCounterL,1); WHILE (CurrentCharL = TextQualifier) OR (CurrentCharL = ColDelimiter) DO BEGIN CurrentCharL := COPYSTR(ImportBuffer,CharCounterL,1); CharCounterL += 1; END; NextParsePoint := CharCounterL - 1; EXIT(NextParsePoint); ClearImportVars() CLEAR(ImportBuffer); CLEAR(ItemNo); CLEAR(ItemDesc); CLEAR(UPC); CLEAR(TypeCode); CLEAR(LastParsingPoint); CLEAR(FirstParsingPoint);
This is kind of rough but you get the idea. I'll post any enhancements once I get finished completely testing and refining this solution. :-k0 -
Hi,
I'm having the same problem regarding dataports and NAS. I am looking at this and I don't understand what is going on with:
ColDelimiter := '|';
TextQualifier := '^';
Is this not supposed to be a tab delimited file (which I'm using too), why do you use the above characters? Do you not use e.g. Char := 9; for the Tab or something? Could anyone shed some more light on this?
Many Thanks0 -
May this blog will help : dynamicslancer.blogspot.in/p/blog-page.html0
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