Skip to main content
Business Central forum
Suggested answer

Send XML port by group of lines

editSubscribe (0) ShareShare
ReportReport
Posted on by 67

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 59,873 Super User 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 32,714 Super User 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 67 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 59,873 Super User 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 32,714 Super User 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 67 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 32,714 Super User 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 67 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 32,714 Super User 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.

Helpful resources

Quick Links

What Motivates a Super User?

We know many of you visit the Dynamics 365 Community and Power Platform…

Demystifying Copilot with Georg Glantschnig…

Industry experts answer burning questions directly from our amazing Community…

Setting Up Knowledge Sources for Copilot…

Look at how configuring a comprehensive knowledge base is crucial…

Leaderboard

#1
Andre Arnaud de Calavon Profile Picture

Andre Arnaud de Cal... 283,030 Super User

#2
Martin Dráb Profile Picture

Martin Dráb 222,562 Super User

#3
nmaenpaa Profile Picture

nmaenpaa 101,138

Product updates

Dynamics 365 release plans