Dataport file name and reading file (automation)

mudevilzmudevilz Member Posts: 4
Dear Navision Guru,

I'm a new to Navision.
What I'm trying to accomplish is automate the process of integration between a web application and Navision.
So the interaction between the both application is a csv file to exchange data.
I manage to create dataport to do the import and export thru the interface.
The tough part is how I automate this process without manual work.
I understand there is a few option in automation. For example Job Scheduler(which need user to log on to Navision) and NAS (need to install the application).
Is there any other option? eg. running for schedule task, batch program or .Net application

I had a few other questions.

1) EXPORT portion -
It is possible for a dataport to extract file automaticly with dynamic file name (eg. PaymentTerm_yyyyMMddhhmmss.txt) ?
How do i write this file to a folder?
The dynamic file name is to prevent the file to be overwritten just in case the previous file is not process yet.

2) IMPORT portion -
How do I read from a folder for the files so that dataport and import the data to Navision database?

Your attention is much appreciated.
Thanks in advance.

Regards,
Navision Noob

Comments

  • kinekine Member Posts: 12,562
    The files in some folders can be read through virtual table File (search for "File table" for how to).

    Name for exported file can be created as you wish, for example for generating string YYYYMMDDHHmmSS you can do
      Something := FORMAT(CurrentDateTime,0,'<Year4><Month,2><Day,2><Hours24,2><Minutes,2><Seconds,2>');
    
    

    Something is text variable, of course you can use returned string in another way...
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • mudevilzmudevilz Member Posts: 4
    Dear Kine,

    Thanks for the usefull reply.
    I manage to do the export portion with file name with timestamp. Cool !! Thanks

    But I unable to get any help from google or APPLICATION DESIGNER’S GUIDE document for virtual table File.
    What I have achieve is creating a Tabular-Type Form with the File table (id=2000000022).
    But not much luck on that because it complain "The File table is read-only" when try to insert a new row in the form.
    Is my direction correct of creating a form to access the File table and set the path there.
    Then use the C/AL to access the object

    Appreciate if you can provide any url or document that can help on this.
    Thanks in advance
  • krikikriki Member, Moderator Posts: 9,118
    In fact, you can't insert or modify records. It is read-only.
    If you want to see some records, you have to put a filter on field "Path" like "C:\WINDOWS\".
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


  • kinekine Member Posts: 12,562
    Yes, this table is read only. You only need to set some filter and you will have records with files which are in the "filter"... :-) It is table-like access to the file directory.
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • mudevilzmudevilz Member Posts: 4
    Dear kine and kriki,

    Thanks for your reply.

    I manage to get the file loading working.
    There is another problem now.
    If there is more than one file detected, when the dataport is execute the second times, the whole Navision "hang" and is saw the error below in Event Viewer
    "Faulting application fin.exe, version 3.60.0.11353, faulting module fin.exe, version 3.60.0.11353, fault address 0x00084c81."

    Any idea why this happen.
    Thanks in advance.

    Below is the portion of my code :

    VAR
    ExpDat@1000000003 : Dataport 50006;

    OnPreDataport=BEGIN
    CurrDataport.FILENAME := FeedPath
    ;
    CLEAR(recFile);
    recFile.SETRANGE(Path, FeedPath);
    recFile.SETRANGE("Is a file", TRUE);
    recFile.SETFILTER(Name, '@s*');
    IF recFile.FIND('-') THEN
    REPEAT
    CurrDataport.FILENAME := FeedPath + recFile.Name;
    CurrDataport.IMPORT(TRUE);
    ExpDat.FILENAME(CurrDataport.FILENAME);
    ExpDat.RUNMODAL;

    UNTIL recFile.NEXT = 0;
    END;
  • kinekine Member Posts: 12,562
    You need to Clear the Dataport before each call (or after each call)...
    CLEAR(ExpDat);
    
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • allenmanallenman Member Posts: 37
    Hello,

    I am almost in the area of double posting but please bear with me, the progress I have made has now brought me to this thread. I am still very new to Navision but very enthusiastic.

    I have a number of txt files to import with a dataport and all works with one file but goes wrong at the second onwards.

    In the post from mudevilz is all this code within the OnPreDataport trigger of the dataport?
    So far I am attempting to repeat the calls for the dataport from a form button, I am under the impression that it must be done outside of the dataport.
    FilePath2 :='C:\ABC\';
    
    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;
    CurrForm.UPDATE(TRUE);
    

    Variable MyFile is a record type of the virtual file "File".

    I then basically repeat this code within my dataport OnPreDataport trigger and delete the file. This bit works.

    When the next txt file is processed the find within the form button code picks up the new txt file name but during the code for the dataport it still finds the original txt file, even though I have cleared it.

    I admit I have a few problems with my understanding of what is going on here. It is as though the virtual table has not been updated.

    Here is some code from the dataport
    Dataport - OnPreDataport()
    //SHELL('c:RGJ\dir');
    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
    EafFileName :=MyFile.Name;
    END;
    
    CurrDataport.FILENAME(FilePath + FileName);
    
    
    Dataport - OnPostDataport()
    Text000  :='OK to delete file ?';
    CurrFile.CLOSE; 
    IF CONFIRM(Text000, TRUE) THEN 
    WHILE EXISTS(CurrDataport.FILENAME) 
    DO ERASE(CurrDataport.FILENAME);
    
    The almost repeat of the code seems that it must be wrong in principle.
    Reading the threads I believe others have got similar to work so I am hopefull.

    Thanks in advance for any help.

    Regards,
    Steve
  • RachelSoonRachelSoon Member Posts: 202
    Hi All,
    i agree with allenman that the file information in the "File" (the virtual table) does not get refresh even though the file has been physically removed from the folder.
    The information in the "File" will be only refresh if we close the Navision application.

    Is there any method to clear the memory for "File"?

    I need to run the dataport which will be reading the "File". This dataport need to be run more than one time a day. Closing the Navision application everytime before running the dataport is not practical.

    Thank you in advance.

    Regards,
Sign In or Register to comment.