Exporting data from two tables

downtapdowntap Member Posts: 18
Hi All,

Here's what I'm trying to do.

I have two tables, a header and a line table. I'd like to output some data from the two, such as

Header1DataItem, Line1DataItem1, Line1DataItem2
Header2DataItem, Line2DataItem1, Line2DataItem2
etc.

The two tables are mainly used on a form/subform. In the example above, the first line is from one form & subform, and the second line is from another form and subform. I do know that I cannot use a dataport to export an indented tables. Is my only option an xml port or a proccessing only report? If so, can anyone give me a nudge in the right direction to try those?

I hope I explained that clearly enough, kind of hard to describe. Thanks in advance for any and all help!

-Patrick

Comments

  • DenSterDenSter Member Posts: 8,304
    Assuming you are working on a dataport, you can export variables as well as fields. use the line table as a dataitem, get the associated header record for each line, and set the variables to the field values.
  • downtapdowntap Member Posts: 18
    Thanks a ton for the help! I'm still somewhat a novice programmer, so bear with me through this.

    Here's what I've started:

    The line table is set as the data item for the dataport.

    In my code I have the following in the OnBeforeExportRecord section:
    HeaderTableVariable := "Header Table Field";
    LineTableVariable := "Line Table Field 1"
    

    Now, obviously I've stripped this down to its core. This, as it should, repeats the header field for every line variable. I'd like the header variable to only print once for all the line variables associated with it. Do I need to code a REPEAT or FOR Loop? Sorry for such a basic question, but programming is definitely not my strong suit in Navision. :)
  • DenSterDenSter Member Posts: 8,304
    Dataports can't be indented, it's always a flat file. You can't have 1 hdr, 2 lines, 1 hdr, 2 lines. Instead you can have 2 lines, 2 lines, and in each line you repeat the values from the header record by using a variable as the sourceexpr for the dataport fields.

    You don't have to program any loop, the dataport's dataitem will do the looping.

    Get a hold of a product disc, and look for a file called w1w1adg.pdf, in the Doc folder. This document contains technical information on how to use dataports. You should also get the C/SIDE Introduction and C/SIDE Development courses. If you don't have access to partnersource or customersource, purchase David Studebaker's book on programming in NAV.
  • downtapdowntap Member Posts: 18
    Ok, maybe this is possible. On one table I have the following data:

    No. SampleField1
    1 Mary
    1 John
    2 Jane
    2 Jack

    Is it possible to write a dataport that outputs this:

    1, Mary, John
    2, Jane, Jack

    Does that make sense at all? Thanks again for the help!
  • DenSterDenSter Member Posts: 8,304
    Sure, you just have to figure out how to 'flatten' the data.
  • downtapdowntap Member Posts: 18
    Just wanted to say thanks, finally got everything working great. As a reference to anyone who might find this thread, I used a processing only report to export the data due to some possibly max line lengths. It worked best anyways as a report since I wrote the file as a .bat file and also have the report run the batch file at the end. Great solution, just trick getting the code to 'flatten' the data. Thanks again.
Sign In or Register to comment.