Import data from text file and insert into Navision table

anilkumaranilkumar Member Posts: 136
Hi Experts,

Can any one help me, how to import data from text file and insert/modify the values of the existing navision tables, but not using dataports.

Anyone had got any idea, how to handle this issue..........
Anil Kumar Korada
Technical Consultant

Comments

  • zeninolegzeninoleg Member Posts: 236
    What do you have access to? Reports? Codeunits? Any CAL code?
    If you have an access to CAL code then you will have to write a program to read file and insert records in the table manually
    Best Regards,
    Oleg
  • anilkumaranilkumar Member Posts: 136
    any CAL/Code sample example please
    Anil Kumar Korada
    Technical Consultant
  • DenSterDenSter Member Posts: 8,305
    What's wrong with dataports? You can create a dataport in about 10 minutes, programming a codeunit to import from a textfile takes hours.
  • anakinanakin Member Posts: 27
    DenSter wrote:
    What's wrong with dataports? You can create a dataport in about 10 minutes, programming a codeunit to import from a textfile takes hours.

    I have the same problem: ok, the dataport is very good for import a text file, but it's possible to launch dataport in automatic manner without user intervent ?

    I must control a directory at regular interval (every hour) and if there are text files in my "rx directory" I must import to navision table.
    This process must be totally automatized; there isn't user intervent.

    Thanks anakin

    Excuse me for my bad english :oops:
  • SavatageSavatage Member Posts: 7,142
    You can use the job scheduler to run jobs automatically at user-defined intervals. For the job you want the scheduler to run, you must specify which object (report, dataport or codeunit) carries out the job and when you want to run it.
  • anakinanakin Member Posts: 27
    Savatage wrote:
    You can use the job scheduler to run jobs automatically at user-defined intervals. For the job you want the scheduler to run, you must specify which object (report, dataport or codeunit) carries out the job and when you want to run it.

    In my "Job Queue Entry Card" I can choose only report e codeunit, not dataport
  • David_CoxDavid_Cox Member Posts: 509
    anakin wrote:
    Savatage wrote:
    You can use the job scheduler to run jobs automatically at user-defined intervals. For the job you want the scheduler to run, you must specify which object (report, dataport or codeunit) carries out the job and when you want to run it.

    In my "Job Queue Entry Card" I can choose only report e codeunit, not dataport

    Create a report, to look for the file, if there is a fle to import, you can then using the dataport as a variable, set the filename, set it as Import, and then run the dataport from the job scheduler!

    :)
    Analyst Developer with over 17 years Navision, Contract Status - Busy
    Mobile: +44(0)7854 842801
    Email: david.cox@adeptris.com
    Twitter: https://twitter.com/Adeptris
    Website: http://www.adeptris.com
  • anakinanakin Member Posts: 27
    >> Create a report, to look for the file, if there is a fle to import...

    What's the mean of "Create a report, to look for the file" ?
    - Must be a non printing report ?
    - What trigger I must coding ?
    - Can you post a report trigger code sample ?

    Thanks, anakin
  • David_CoxDavid_Cox Member Posts: 509
    Create a Process Only report, and on pre report you run your code, you need to use variables, for your Dataport, and in a setup somewhere hold the path to where your files are stored, also a path to move the files to after Import.

    Here is a small part of the code, this will Import and Move the first file, but you will need to code to move Invalid files.

    The reason this only brings in one file at a time is because we are using RUNMODAL for the dataport, this means the dataport will run and close the file before we move it.

    MyFiles is a variable Type = Record and Name = File
    MySetup.GET;
    MySetup.TESTFIELD("File Path");
    MySetup.TESTFIELD("History File Path");
    
    MyFiles.SETRANGE(Path,MySetup."File Path");
    MyFiles.SETRANGE("Is a file",TRUE);
    IF MyFiles.FINDFIRST THEN BEGIN 
         FileName[1]:=MySetup."File Path"+MyFiles.Name;
         FileName[2]:=MySetup."History File Path"+MyFiles.Name;
         CLEAR(MyDataPort);
         //Code Here to set the filename and Run the dataport
         MyDataport.FILENAME := FileName[1];
         MyDataport.IMPORT := TRUE; 
         MyDataport.RUNMODAL;
         //This code will move the file to history
         IF FILE.EXISTS(FileName[1])THEN
             FILE.RENAME(FileName[1],FileName[2]);
     END;
    CurrReport.BREAK;
    

    David
    Analyst Developer with over 17 years Navision, Contract Status - Busy
    Mobile: +44(0)7854 842801
    Email: david.cox@adeptris.com
    Twitter: https://twitter.com/Adeptris
    Website: http://www.adeptris.com
  • anakinanakin Member Posts: 27
    Thanks for all,
    but if I use a codeunit instead of report is the same ?
  • David_CoxDavid_Cox Member Posts: 509
    anakin wrote:
    Thanks for all,
    but if I use a codeunit instead of report is the same ?

    Yes, sure use a codeunit, reports were often used as default because the Client often had Reports but not Codeunits on the licence.

    David
    Analyst Developer with over 17 years Navision, Contract Status - Busy
    Mobile: +44(0)7854 842801
    Email: david.cox@adeptris.com
    Twitter: https://twitter.com/Adeptris
    Website: http://www.adeptris.com
  • anakinanakin Member Posts: 27
    David Cox wrote:
    Create a Process Only report, and on pre report you run your code, you need to use variables, for your Dataport, and in a setup somewhere hold the path to where your files are stored, also a path to move the files to after Import.

    Here is a small part of the code, this will Import and Move the first file, but you will need to code to move Invalid files.

    The reason this only brings in one file at a time is because we are using RUNMODAL for the dataport, this means the dataport will run and close the file before we move it.

    MyFiles is a variable Type = Record and Name = File
    MySetup.GET;
    MySetup.TESTFIELD("File Path");
    MySetup.TESTFIELD("History File Path");
    
    MyFiles.SETRANGE(Path,MySetup."File Path");
    MyFiles.SETRANGE("Is a file",TRUE);
    IF MyFiles.FINDFIRST THEN BEGIN 
         FileName[1]:=MySetup."File Path"+MyFiles.Name;
         FileName[2]:=MySetup."History File Path"+MyFiles.Name;
         CLEAR(MyDataPort);
         //Code Here to set the filename and Run the dataport
         MyDataport.FILENAME := FileName[1];
         MyDataport.IMPORT := TRUE; 
         MyDataport.RUNMODAL;
         //This code will move the file to history
         IF FILE.EXISTS(FileName[1])THEN
             FILE.RENAME(FileName[1],FileName[2]);
     END;
    CurrReport.BREAK;
    

    David


    >>MyDataport.RUNMODAL;

    this line show the form for select the file to import, but I don't see this form because the file to import is set by FILENAME property and the import must not require user intervent
  • PeterDPeterD Member Posts: 66
    Use the force... :mrgreen:

    Or set Dataport property UseReqForm to No
  • bluesky29bluesky29 Member Posts: 29
    if you use the NAS with the parameter JOBQUEUE to start a codeunit or a report which calls a dataport, the Job Queue Response says:

    "You cannot use C/AL variables of type DATAPORT when running the Microsoft Dynamics NAV Application Server."

    is there any solution to fix this problem ?

    surely i can create a report which imports the file but this means a lot of extrawork.
  • todrotodro Member Posts: 117
    bluesky29 wrote:
    if you use the NAS with the parameter JOBQUEUE to start a codeunit or a report which calls a dataport, the Job Queue Response says:

    "You cannot use C/AL variables of type DATAPORT when running the Microsoft Dynamics NAV Application Server."

    is there any solution to fix this problem ?

    surely i can create a report which imports the file but this means a lot of extrawork.
    Sorry, I'm not aware of any workaround except creating a processing-only report or codeunit. Simply instanciating a dataport is enough to choke (like forms), even if you do not "show" (run) it but try to access a function within it.
    Torsten
    MCP+I, MCSE NT, Navision MCT (2004,2005)
  • andy76andy76 Member Posts: 616
    I have the same problem.
    I wrote 10 complex dataport and I have this message using Job Scheduler.

    Is there any solution without rewrite the dataport as report?
    ](*,)

    Andy
Sign In or Register to comment.