Pass FILENAME to Dataport - Virtual Table Update ?

allenman
Member Posts: 37
Hello all.
Some of what I am asking help on has been covered in other posts, indeed I have recieved help with this problem in the relevent area.
However, as more than one technique may be possible, instead of posting to multiple threads I have decided to start a new one with a full list.
I hope this is acceptable.
I am still new to programming Navision, this is only my second project. I have not started this new thread lightly ( I have used the searches) and I have spent the last week on and off looking at this problem. As I am still stuck I want to give it one last try. Apologies if I have broken any rules with this.
I wish to import multiple "|" delineated text files using a dataport from a fixed directory. As these text files are processed they are moved to an achive dir. New text files may be added at any time.
My problem to resolve is how to pass the text file name to the dataport.
Method 1
This involves using the virtual table "File" 2000000022.
It has been duscussed here http://www.mibuso.com/forum/viewtopic.php?t=9635&highlight=dataport and here http://www.mibuso.com/forum/viewtopic.php?t=1633&highlight=virtual
My code is called from the form to loop calls to the dataport dependent on record variable file.name.
The dataport code looks like this:
This almost works. During a first pass the files data are correctly inserted and the files coped to the new directory and then the original deleted.
I have two problems with this:
1- If I rerun the code I find that the virtual table has not been updated, it still sees the original file list. So my code does not run the dataport if the primary key alrady exists. But I still get a Navision error of
2- As new files are added to the directory because the virtual table is not updated they are not detected. If I shut the form down and re-open it is sometimes ok. Can anyone help me "re-fresh" the virtual table?
Method 2
How To pass parameters between objects (forms, reports, ...)?
http://www.mibuso.com/howtoinfo.asp?FileID=7&Type=howto
I found this really interesting and informative.
I do not use a User Request Form, so I tried loading the text file name into global variables but the info was lost between the calling of the function from my form to the calling of the dataport from the same form.
I was thinking along the lines of:
So instead, could I use a uesr request form to hold the passed text filename but have it hidden and processed automatically?
Method 3
I have also come across this technique which avoids the use of the virtual table.
[SOLVED] Windows Script Host Object Model Folders and Files.
http://www.mibuso.com/forum/viewtopic.php?t=7855&highlight=virtual
I have not been able to make any in-roads into using this. If anyone agrees this may help could they provide some more info on how to implement it?
I know I am asking a lot I can only apologise.
Regards,
Steve
Some of what I am asking help on has been covered in other posts, indeed I have recieved help with this problem in the relevent area.
However, as more than one technique may be possible, instead of posting to multiple threads I have decided to start a new one with a full list.
I hope this is acceptable.
I am still new to programming Navision, this is only my second project. I have not started this new thread lightly ( I have used the searches) and I have spent the last week on and off looking at this problem. As I am still stuck I want to give it one last try. Apologies if I have broken any rules with this.
I wish to import multiple "|" delineated text files using a dataport from a fixed directory. As these text files are processed they are moved to an achive dir. New text files may be added at any time.
My problem to resolve is how to pass the text file name to the dataport.
Method 1
This involves using the virtual table "File" 2000000022.
It has been duscussed here http://www.mibuso.com/forum/viewtopic.php?t=9635&highlight=dataport and here http://www.mibuso.com/forum/viewtopic.php?t=1633&highlight=virtual
My code is called from the form to loop calls to the dataport dependent on record variable file.name.
FilePath2 :='C:\RGJ\'; CLEAR(MyFile2); MyFile2.RESET; MyFile2.SETRANGE(Path,FilePath2); MyFile2.SETRANGE("Is a file",TRUE); MyFile2.SETFILTER(Name, '@*.txt'); IF MyFile2.FIND('-') THEN BEGIN REPEAT DATAPORT.RUN(50038, FALSE) UNTIL MyFile2.NEXT = 0; END ELSE BEGIN MESSAGE ('All text files have been processed.'); EXIT; END;
The dataport code looks like this:
Dataport - OnPreDataport() FilePath :='C:\ABC\'; //MyFile.INIT; CLEAR(MyFile); MyFile.RESET; MyFile.SETRANGE(Path,FilePath); MyFile.SETRANGE("Is a file",TRUE); MyFile.SETFILTER(Name, '@*.txt'); IF MyFile.FIND('-') THEN BEGIN REPEAT FileLength :=STRLEN(MyFile.Name)- 4; PSSName := COPYSTR(MyFile.Name,1,FileLength); IF NOT SdcRecord.GET(PSSName) THEN BEGIN FileName :=MyFile.Name; CurrDataport.FILENAME(FilePath + FileName); EXIT; END; // IF MyFile.NEXT = 0 THEN EXIT; UNTIL MyFile.NEXT = 0; END; CurrDataport.QUIT; MESSAGE ('All text files have been processed.'); Dataport - OnPostDataport() CompletedPath :='C:\ABC\Completed\'; CurrFile.CLOSE; COPY(FilePath + FileName, CompletedPath + FileName); WHILE EXISTS(CurrDataport.FILENAME) DO ERASE(CurrDataport.FILENAME);
This almost works. During a first pass the files data are correctly inserted and the files coped to the new directory and then the original deleted.
I have two problems with this:
1- If I rerun the code I find that the virtual table has not been updated, it still sees the original file list. So my code does not run the dataport if the primary key alrady exists. But I still get a Navision error of
I just cannot get my head around this error. Can anyone help me stop this message ?The operating system cannot find the drive and directory specified for the file .
Please check that the drive, directory and file name are correct.
2- As new files are added to the directory because the virtual table is not updated they are not detected. If I shut the form down and re-open it is sometimes ok. Can anyone help me "re-fresh" the virtual table?
Method 2
How To pass parameters between objects (forms, reports, ...)?
http://www.mibuso.com/howtoinfo.asp?FileID=7&Type=howto
I found this really interesting and informative.
I do not use a User Request Form, so I tried loading the text file name into global variables but the info was lost between the calling of the function from my form to the calling of the dataport from the same form.
I was thinking along the lines of:
IF MyFile2.FIND('-') THEN BEGIN REPEAT CLEAR(MyDataPort); FileName := MyFile2.Name; MyDataPort.fctSetFileName(FileName,FilePath); DATAPORT.RUNMODAL(50038, FALSE) UNTIL MyFile2.NEXT = 0; END ELSE BEGIN MESSAGE ('All text files have been processed.'); EXIT; END; END;and
PROCEDURE fctSetFileName@1000000000(pFileName@1000000000 : Text[40];pFilePath@1000000001 : Text[50]); BEGIN FileName := pFileName; FilePath := pFilePath; //DATAPORT.RUNMODAL(50038, FALSE); END;
So instead, could I use a uesr request form to hold the passed text filename but have it hidden and processed automatically?
Method 3
I have also come across this technique which avoids the use of the virtual table.
[SOLVED] Windows Script Host Object Model Folders and Files.
http://www.mibuso.com/forum/viewtopic.php?t=7855&highlight=virtual
I have not been able to make any in-roads into using this. If anyone agrees this may help could they provide some more info on how to implement it?
I know I am asking a lot I can only apologise.
Regards,
Steve
0
Answers
-
For importing you can use something like that:
CLEAR(Files); Files.RESET; Files.SETFILTER(Path,'C:\'); //to refresh data if the GetImportDir is still same Files.SETFILTER(Path,'%1',GetImportDir); Files.SETFILTER(Name,'%1','*.txt'); Files.SETRANGE("Is a file",TRUE); IF Files.FIND('-') THEN REPEAT CLEAR(Imp); Imp.FILENAME(GetImportDir+Files.Name); Imp.RUNMODAL; COMMIT; UNTIL Files.NEXT=0;
The Imp is variable of type DATAPORT.0 -
Dataport - OnPostDataport() CompletedPath :='C:\ABC\Completed\'; CurrFile.CLOSE; COPY(FilePath + FileName, CompletedPath + FileName); WHILE EXISTS(CurrDataport.FILENAME) DO ERASE(CurrDataport.FILENAME);
May be that problem is that CurrDataport.FILENAME is cleared when the CurrFile.CLOSE is called...0 -
Regarding the ErrorThe operating system cannot find the drive and directory specified for the file.
Please check that the drive, directory and file name are correct.
As you've figured out the File record set has not been
updated, the trick is to make Navision point to another
path and then set it back to path you would like to scan.MyFile.RESET; MyFile.SETRANGE("Is a file",TRUE); // >> [Fix Refresh Problem] - Tarek 06.04.2006 MyFile.SETRANGE(Patch, 'C:\'); // Set it to any existing path which is different than FilePath IF MyFile.FIND('-') THEN; // Force Navision to retrieve the first file // << [Fix Refresh Problem] - Tarek 06.04.2006 MyFile.SETRANGE(Path,FilePath); MyFile.SETFILTER(Name, '@*.txt');
Kamil :
If you do not perform a IF MyFile.FIND('-') THEN; after the SETRANGE Navision do not update the record set (at least on my system WinXP with Nav 3.6)0 -
Yes, it is possible, that is part from old object of 2.60 database... :-)0
-
kine and Tarek Demiati, thank you so much.
To get it fully working I needed to repeat the Find as Tarek Demiati stated.
Thank you both for the content and speed of your replies.
For anyone else here is a summery of the working codeFilePath2 :='C:\ABC\'; Root := COPYSTR(FilePath2,1,3); CompletedPath :='C:\ABC\Completed\'; CLEAR(MyFile2); MyFile2.RESET; MyFile2.SETRANGE("Is a file",TRUE); MyFile2.SETFILTER(Path,Root); //Refresh Virtual Table if data changed IF MyFile2.FIND('-') THEN; // Force Navision to retrieve the first file MyFile2.SETFILTER(Path,'%1',FilePath2); MyFile2.SETFILTER(Name,'%1', '@*.txt'); MyFile2.SETRANGE("Is a file",TRUE); IF MyFile2.FIND('-') THEN BEGIN REPEAT CLEAR(MyDataPort); MyDataPort.FILENAME(FilePath2 + MyFile2.Name); MyDataPort.RUNMODAL;// DATAPORT.RUN(50038, FALSE) FILE.COPY(FilePath2+MyFile2.Name, CompletedPath+MyFile2.Name); WHILE EXISTS(FilePath2+MyFile2.Name) DO ERASE(FilePath2+MyFile2.Name); COMMIT; UNTIL MyFile2.NEXT = 0; END ELSE BEGIN MESSAGE ('All text files have been processed.'); EXIT; END;
Variables:Name DataType Subtype MyFile2 Record File MyDataPort Dataport CourierDP
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
- 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