skipping dataport-- need help
Gil
Member Posts: 49
Here i have is a code that will automatically load textfiles on dataport, but is there any way to skip the current textfile if it encounters an error?
Folder := 'C:\Sales Import';
FileSystem.SETRANGE(FileSystem.Path, Folder);
FileSystem.SETRANGE(FileSystem."Is a file", TRUE);
FileSystem.SETFILTER(FileSystem.Name, '@*.txt');
IF FileSystem.FIND('-') THEN BEGIN
REPEAT
//MESSAGE(FileSystem.Name);
old_name := '';
new_name := '';
file_name := FileSystem.Name; //for counting
old_name := FileSystem.Path + '\' + FileSystem.Name;
new_name := FileSystem.Path + '\' + file_name;
//MESSAGE('%1',STRLEN(file_name));
file_to_import := FileSystem.Path + '\' + FileSystem.Name;
IF STRLEN(file_name) = 19 THEN BEGIN
//MESSAGE(FORMAT(STRLEN(file_name)));
IF EXISTS(file_to_import) THEN BEGIN
//MESSAGE(FileSystem.Name);
IF FileSystem.Size <> 0 THEN BEGIN
//CLEAR(DataportObject);
//DataportObject.SetFileName(file_to_import);
DataportObject.FILENAME(file_to_import);
DataportObject.IMPORT(TRUE);
DataportObject.RUNMODAL;
[b] ///SKIP HERE ON ERROR <--------------[/b]
END;
//to rename in to new name
RENAME(old_name, new_name);
IF COPY(FileSystem.Path + '\' + FileSystem.Name, FileSystem.Path + '\Imported\' + FileSystem.Name) THEN
//MESSAGE(old_name);
ERASE(FileSystem.Path + '\' +FileSystem.Name);
END;
END;
UNTIL FileSystem.NEXT = 0;
END;
MESSAGE('DONE');
0
Comments
-
I think the route you need at the end '\'
Folder := 'C:\Sales Import\'
EDIT: sorry, I just realized that this is not the error0 -
as you can see i set the dataport.filename = textfile then runs it..
i dont know how to skip the textfile if it encounters any error0 -
What is the error that can be found? if you know, I can help0
-
Do no run the dataport from your function but encapsulate it inside a Codeunit and run the CU with if CU.run instead:
Instead ofGil wrote:IF FileSystem.Size <> 0 THEN BEGIN //CLEAR(DataportObject); //DataportObject.SetFileName(file_to_import); DataportObject.FILENAME(file_to_import); DataportObject.IMPORT(TRUE); DataportObject.RUNMODAL; [b] ///SKIP HERE ON ERROR <--------------[/b] END;
Do something like this:IF FileSystem.Size <> 0 THEN BEGIN clear(CUFileImport); CUFileImport.SetParamas(...) if CUFileImport.run... then ... END; Inside of CUFileImport: //CLEAR(DataportObject); //DataportObject.SetFileName(file_to_import); DataportObject.FILENAME(file_to_import); DataportObject.IMPORT(TRUE); DataportObject.RUNMODAL;Frank Dickschat
FD Consulting0 -
i don't think this is a solution.
i'd give you a scenario, if there was an error on textfile lets say:
!1!|!Sales!|!00A0000001!|!LOCAL!|!000100!|
But i insert instead
?!1!|!Sales!|!00A0000001!|!LOCAL!|!000100!|
we would a receive an error that it cant import.
On my code it has a loop, when getting an error like this it should skip that textfile0 -
FDickschat already gave you the solution. put it into codeunit and use IF Codeunit.RUN THEN.
Nav will not throw any error message, and will continue executing the next command.Microsoft Certified IT Professional for Microsoft Dynamics NAV
Just a happy frood who knows where his towel is0
Categories
- All Categories
- 75 General
- 75 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
- 610 NAV Courses, Exams & Certification
- 1.9K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 251 Dynamics CRM
- 103 Dynamics GP
- 6 Dynamics SL
- 1.5K Other
- 991 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 28 Design Patterns (General & Best Practices)
- Architectural Patterns
- 9 Design Patterns
- 4 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1K General Chat
- 1.6K Website
- 77 Testing
- 1.2K Download section
- 23 How Tos section
- 249 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions