web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Small and medium business | Business Central, N...
Suggested Answer

Send XML port by group of lines

(0) ShareShare
ReportReport
Posted on by 108

Hi 

I have created an xmlport object and I can download an XML type file with all the records of the table. 
My table has 10,000 records and I need to send XML files with 2,000 records until I complete 10,000 records.
How can I generate the 5 files iterating from 2,000 to 2,000?

I think the algorithm is something like this but I'm not sure, is there another way to do it?

The "Year" and "FormatNo" are Key from the table.
                    DMM_DetalleTable.SetFilter("DMM_AñoDeclaracion", '%1', Rec."Year");
                    DMM_DetalleTable.SetFilter(DMM_FormatNo, Rec.FormatNo);
                    if DMM_CXPDetalleTable.Find() then
                        repeat
                            copy to tmpTable
                            if conunt = 2000 then begin
                                TempBlob.CreateOutStream(MyOutStream);
                                Xmlport.Export(60101, MyOutStream, tmptable);
                                TempBlob.CreateInStream(MyInStream);
                                outputFileName := 'myNameFile.XML';
                                DownloadFromStream(MyInStream, '', '', '', outputFileName);
                                clear(tmpTable)
                                conunt=0;
                            end;
                            conunt= conunt+1;
                        until DMM_CXPDetalleTable.Next() = 0;
 
  • Suggested answer
    IB-29041624-0 Profile Picture
    1,191 Moderator on at

    Are you running BC online or BC on prem?

    With your code you will get the same 2000 records every time you run the code.

    So you need to put a filter somewhere so you know you are getting another set of your record each time.

    If you run on prem i would export the data directly from my SQL server.

  • CPRM Profile Picture
    108 on at

    I have BC on line,

  • Suggested answer
    IB-29041624-0 Profile Picture
    1,191 Moderator on at

    Maybe you can put filter on year then and produce one file for every year?

  • CPRM Profile Picture
    108 on at

    But if I have more than 2.000 by year , will not work.

    I am thinking to give a column with Id  from 1 to the number  that I will need after call a setrange filter  iterating 2.000 by 2.000 until latest record.

  • Suggested answer
    IB-29041624-0 Profile Picture
    1,191 Moderator on at

    Yeah if you can not do it year by year you have to find an additional field to filter on.

    Using an ID sounds like a good alternative. But i do not see the whole structure of your data table so it is a bit hard to be very specific in my advice.

  • Suggested answer
    YUN ZHU Profile Picture
    103,797 Super User 2026 Season 2 on at

    Hi, Sorry I haven't tested it specifically.
    But I think it's possible to add a new field to the table, like Number.
    Each time it is exported, +1, when it reaches 2000, re-read this table and only filter this field is empty. After the export is complete, clear the value of this field.

    Hope this can give you some hints.

    Thanks.

    ZHU

  • CPRM Profile Picture
    108 on at

    I was finally able to download as many XML files as I need. Each with the number of records I required

    pastedimage1664837473288v1.png

    The only bad thing is that I have to send a message every time I download a file so that it doesn't overwrite it.

    you know if there is a better way than to send a message and have the user click every time a file is downloaded? 

    a procedure is this:

     procedure GenerarArchivoXML(MyOutStream: OutStream; MyInStream: InStream; var DMM_CXPDetalleTableImpr: Record DMM_CXPDetalleTable; outputFileNameImp: Text)
        begin
            clear(MyOutStream);
            clear(MyInStream);
            TempBlob.CreateOutStream(MyOutStream);
            Xmlport.Export(60101, MyOutStream, DMM_CXPDetalleTableImpr);
            TempBlob.CreateInStream(MyInStream);
            DownloadFromStream(MyInStream, 'Exportando', '', '', outputFileNameImp);

            if Confirm('confirm' + outputFileNameImp) then;
        end;
    and yes, Zhu Yun, I had to add a new field to write a number of record like this:
                                id_No := 1;
                                repeat
                                    DMM_CXPDetalleTable.DMM_NoImpresionXML := id_No;
                                    id_No := id_No + 1;
                                    DMM_CXPDetalleTable.Modify();
                                until DMM_CXPDetalleTable.Next() = 0;
    and the filter es like this:
    limit := 2.000
                                   loop start......
                                    start := end + 1;
                                    end := start + limit  - 1;
                                    DMM_CXPDetalleTable.SetFilter("DMM_AñoDeclaracion", '%1', Rec."DMM_AñoDeclaracion");
                                    DMM_CXPDetalleTable.SetFilter(DMM_FormatNo, Rec.DMM_FormatNo);
                                    DMM_CXPDetalleTable.SetRange(DMM_NoImpresionXML, start, end);
    I appreciate if you know a solution for the subject of the message with confirmation by file
  • Suggested answer
    IB-29041624-0 Profile Picture
    1,191 Moderator on at

    If you do not want the users to interact during the file download i think your best option would be to store the files in an Azure blob storage. AL have support for that now so you can use that as a storage alternative to your local disk.

  • Suggested answer
    YUN ZHU Profile Picture
    103,797 Super User 2026 Season 2 on at

    Hi, How about adding these three files to the zip file before downloading?

    Adding multiple files into a zip file

    https://yzhums.com/20030/

    Hope this helps.

    Thanks.

    ZHU

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Leaderboard > Small and medium business | Business Central, NAV, RMS

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 795 Super User 2026 Season 2

#2
YUN ZHU Profile Picture

YUN ZHU 561 Super User 2026 Season 2

#3
Grigorios Mavrogeorgis Profile Picture

Grigorios Mavrogeorgis 323 Super User 2026 Season 2

Last 30 days Overall leaderboard

Featured topics

Microsoft Training Manuals

Product updates

Dynamics 365 release plans