Skip to main content

Notifications

Announcements

No record found.

Small and medium business | Business Central, N...
Suggested answer

Send XML port by group of lines

(0) ShareShare
ReportReport
Posted on by 78

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
    YUN ZHU Profile Picture
    YUN ZHU 75,942 Super User 2024 Season 2 on at
    RE: Send XML port by group of lines

    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

  • Suggested answer
    Inge M. Bruvik Profile Picture
    Inge M. Bruvik 993 Super User 2024 Season 1 on at
    RE: Send XML port by group of lines

    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.

  • CPRM Profile Picture
    CPRM 78 on at
    RE: Send XML port by group of lines

    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
    YUN ZHU Profile Picture
    YUN ZHU 75,942 Super User 2024 Season 2 on at
    RE: Send XML port by group of lines

    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

  • Suggested answer
    Inge M. Bruvik Profile Picture
    Inge M. Bruvik 993 Super User 2024 Season 1 on at
    RE: Send XML port by group of lines

    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.

  • CPRM Profile Picture
    CPRM 78 on at
    RE: Send XML port by group of lines

    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
    Inge M. Bruvik Profile Picture
    Inge M. Bruvik 993 Super User 2024 Season 1 on at
    RE: Send XML port by group of lines

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

  • CPRM Profile Picture
    CPRM 78 on at
    RE: Send XML port by group of lines

    I have BC on line,

  • Suggested answer
    Inge M. Bruvik Profile Picture
    Inge M. Bruvik 993 Super User 2024 Season 1 on at
    RE: Send XML port by group of lines

    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.

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

Congratulations 2024 Spotlight Honorees

Kudos to all of our 2024 community stars! 🎉

Meet the Top 10 leaders for December

Congratulations to our December super stars! 🥳

Start Your Super User Journey

Join the ranks of our community heros! 🦹

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,784 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,476 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans