XMLPort (Export, FixedVariable format) - nested loops?

alex9alex9 Member Posts: 97
Is it possible to create nested loops in XMLPort, which is used for exporting txt file?

My XMLPort successfully creates txt file - one row per each record in my table. But I need some extra rows in the exported txt file - headers and trailers. it's like GroupHeader and GroupFooter in classic report. Something like that:
Header1
Line1
Line2
Trailer1
Header2
Line3
Line4
Trailer2

I need to retrieve Header, Line and Trailer values from the same table, but Header row in txt file has different structure (obviuosly) than Line row. I know, how to create Header once, using Integer. But I do not know how to creater Header2 and get back to line structure again. I was goint to use nested loops, but XMLPort does not allow to set different indentation for the element = table.

Any tricks?

Comments

  • alex9alex9 Member Posts: 97
    Thanks, Daniel, but your video is about import, and I am using XML for export data from NAV to text file.
    How would you use XMLPort to export several purchase invoices, so in text file you would have data from the purchase header in the first row, then several rows from purchase line, then another row from the next purchase invoice header, then its lines, etc. ? Is it possible with XMLPort?
  • DenSterDenSter Member Posts: 8,307
    Import, Export, it all works the same. You flatten the file to get it all out to a flat text file. Because you can't have nested dataitems when working with flat text files, you will have to program the XMLPort to take care of the data. In your case I would probably create an XMLPort based on the line table, exporting everything to variables, and programming the dataitem to fetch the header information that belongs to the current line. Be creative, try out different things, see what happens when you change it around.

    Instead of thinking 1 header, multiple lines, you need to think about repeating the header values for each line, like I did in the example. The text file that I show at the start of the demo (the one with multiple lines for the second invoice) is your target file format. You could theoretically think about not repeating the header fields but only showing those once, but I actually like the repeating nature because it clearly shows all relevant attributes, which is especially useful if you have large numbers of lines per document.

    If you want the nested tables idea, you'll have to use XML, text files can't be formatted that way. Unfortunately those are the limitations of XMLPorts.
  • alex9alex9 Member Posts: 97
    Unfortunately, I cannot change a structure of the exported file, as it has fixed format and supposed to be submitted to the 3-rd party system.

    In fact, I already have all necessary data in one single table, the only problem is grouping. I have several groups and I have to create header and trail for each group and all of this should be in the one text file. I don't think there is a way to create more than one row in text file per record in the table with the XMLPort, right?
    I think I need to forget about XML Port and use REPEAT ..UNTIL to loop through the table and write data to the File variable. With that, I can create as many extra rows (headers/trails) as I need based on my data.

    Thanks anyways!
  • DenSterDenSter Member Posts: 8,307
    It does sound like using an XMLPort is not the way for this particular one, and you'll have to program writing to the file yourself.
  • ppavukppavuk Member Posts: 334
    alex9 wrote:
    I think I need to forget about XML Port and use REPEAT ..UNTIL to loop through the table and write data to the File variable. With that, I can create as many extra rows (headers/trails) as I need based on my data.

    This is right answer!
Sign In or Register to comment.