Dataport export, Header and Lines

ImaspalImaspal Member Posts: 68
Hi!
How is it possible to export information from Header-table and Line-table (eg. Purchase Header and Purchase Line) to txt-file so, that on the txt-file there is first information from the Header-table and after that information from the Line-table. The information on the txt-file have to be something like that:
    1. Header-table information from order 1 1. Line-table information from order 1 (here can be many lines) 2. Header-table information from order 2 2. Line-table information from order 2 (here can be many lines) 3. Header-table information from order 3 3. Line-table information from order 3 (here can be many lines) etc.
I hope you get the idea and help me with this one..

-Imaspal

Comments

  • SavatageSavatage Member Posts: 7,142
    Sure, you'll have to loop the report - like the invoice report and have the report export the data to a file.

    Dataport - i'm not so sure about.
  • ara3nara3n Member Posts: 9,256
    I agree with savatage. Don't try it with dataport.

    Create a report or Codeunit and loop through header then through line.
    Your code should like this.

    MyFile.create('c:\test.txt');
    MyFile.textmode(true);
    MyFile.WriteMode(true);


    If SalesHeader.findset then repeat
    MyFile.write(SalesHeader."No." + ' ' + SalesHeader."Sell-to customer No.");
    SalesLine.setrange("Document type",SalesHeader."Document type");
    SalesLine.setrange("Document No.", SalesHeader."No.");
    if SalesLine.findset then repeat
    MyFile.write(SalesLine."No." + ' ' + SalesHeader."description");
    until SalesLine.next = 0;

    until SalesHeader.next = 0;

    MyFile.close
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • kinekine Member Posts: 12,562
    Have you some system to mark which line is header and which is the document line? without it you will be not able to import it back or process in some system...
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • ImaspalImaspal Member Posts: 68
    Thanks a lot for your help. Especially thanks for ara3n, the code you gave worked just fine.

    -Imaspal
  • ara3nara3n Member Posts: 9,256
    you are welcome.
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • EugeneEugene Member Posts: 309
    you should put two data items on your dataport and intent lines item relative to header item
    then you link them by setting on the lines item its DataItemLink property
    (the DataItemLinkReference is set automatically by designer)

    take a look at report 107 for example to see how Sales Lines is linked to Customer via DataItemLink property:

    "Sales Line"."Bill-to Customer No."=Customer."No.",
  • ara3nara3n Member Posts: 9,256
    Intend does not work with data ports.
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • EugeneEugene Member Posts: 309
    Just checked it and indeed - there even was a question about it in exam :)
  • ara3nara3n Member Posts: 9,256
    Try and run it.
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
Sign In or Register to comment.