How can i import a data to navision without the XmlPort

Mounika22Mounika22 Member Posts: 18
I should Write a Code unit

Best Answer

Answers

  • Supremenerd88Supremenerd88 Member Posts: 21
    You can write a custom codeunit or a custom report, open file and stream and read data from the stream. I prefer codeunit and i always use this example code:
    MyFile.OPEN(FullFileName);
    MyFile.CREATEINSTREAM(StreamInTest);
    WHILE NOT StreamInTest.EOS DO BEGIN
      StreamInTest.READTEXT(Buffer);
      // insert here your code
    END;
    MyFile.CLOSE();
    

    MyFile is a File variable, StreamInTest is a InStream variable and Buffer is a text variable.
    Giorgio Gandolfi
  • krikikriki Member, Moderator Posts: 9,115
    You can use a dataport in the older versions. But those don't work with the NAS.
    Something that works with all versions is a codeunit and using a FILE variable (and with the newer versions best use also a stream instead of reading/writing directly to the file-variable).
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


  • mdPartnerNLmdPartnerNL Member Posts: 802
    You can write a custom codeunit or a custom report, open file and stream and read data from the stream. I prefer codeunit and i always use this example code:
    MyFile.OPEN(FullFileName);
    MyFile.CREATEINSTREAM(StreamInTest);
    WHILE NOT StreamInTest.EOS DO BEGIN
      StreamInTest.READTEXT(Buffer);
      // insert here your code
    END;
    MyFile.CLOSE();
    

    MyFile is a File variable, StreamInTest is a InStream variable and Buffer is a text variable.

    But in RTC you first need to copy the file to the server, correct?
  • Supremenerd88Supremenerd88 Member Posts: 21
    You can write a custom codeunit or a custom report, open file and stream and read data from the stream. I prefer codeunit and i always use this example code:
    MyFile.OPEN(FullFileName);
    MyFile.CREATEINSTREAM(StreamInTest);
    WHILE NOT StreamInTest.EOS DO BEGIN
      StreamInTest.READTEXT(Buffer);
      // insert here your code
    END;
    MyFile.CLOSE();
    

    MyFile is a File variable, StreamInTest is a InStream variable and Buffer is a text variable.

    But in RTC you first need to copy the file to the server, correct?

    I prefer to use shared folder (i.e. \\192.168.1.100\share\file.txt) but yes, generally you need to copy file on server.
    Giorgio Gandolfi
  • Mounika22Mounika22 Member Posts: 18
    Thanks,
    How should i add my code just give a example.
  • mdPartnerNLmdPartnerNL Member Posts: 802
    above example is already given
  • Supremenerd88Supremenerd88 Member Posts: 21
    edited 2016-03-07
    Mounika22 wrote: »
    Thanks,
    How should i add my code just give a example.

    hypothesize we need to import employees and we have a file lyke this
    E00001Michael             Red                 
    E00002Bill                Green               
    E00003Jim                 Black
    

    the code will be like this:
    MyFile.OPEN(FullFileName);
    MyFile.CREATEINSTREAM(StreamInTest);
    WHILE NOT StreamInTest.EOS DO BEGIN
      StreamInTest.READTEXT(Buffer);
      CLEAR(Emp);
      Emp.INIT();
      Emp.VALIDATE("No.", COPYSTR(Buffer,1,6));
      Emp.VALIDATE("First Name", COPYSTR(Buffer,7,20));
      Emp.VALIDATE("Last Name", COPYSTR(Buffer,27,20));
      Emp.INSERT(TRUE);
    END;
    MyFile.CLOSE();
    

    Emp is a record of Employee variable.
    Giorgio Gandolfi
  • Mounika22Mounika22 Member Posts: 18
    Thank You for your kind reply
Sign In or Register to comment.