How to export data using TextBuilder in Business central.

Amol SalviBusiness Central2 years ago28 Views

Today we will see how we can data from business central table using new data type Text Builder.

To check how this data type work build small program as below which pick up data from customer table and export the data in text file.

pageextension 50101 CustomerMasterExtension extends "Customer List"
{
    actions
    {
        addlast(General)
        {
            action(DataExport)
            {
                Caption='Data Export to Text';
                ApplicationArea=All;
                PromotedCategory=Process;
                Promoted=true;
                Image=ExportDatabase;
                trigger OnAction()
                var
                CustomerMaster :Record Customer;
                Tempblob:Codeunit "Temp Blob";
                TextFileBuilder :TextBuilder;
                FileName:Text;
                InStreamData:InStream;
                OutStreamData:OutStream;
                begin 
                    FileName:='CustomerData.Txt';
                    TextFileBuilder.AppendLine('Customer No'+','+'Customer Name'+','+'Balance');
                    If CustomerMaster.FindSet() then repeat
                        CustomerMaster.SetAutoCalcFields(CustomerMaster.Balance);
                        TextFileBuilder.AppendLine(CustomerMaster."No."+','+CustomerMaster.Name+','+Format(CustomerMaster.Balance));
                    until CustomerMaster.Next()=0;
                    Tempblob.CreateOutStream(OutStreamData);
                    OutStreamData.WriteText(TextFileBuilder.ToText());
                    Tempblob.CreateInStream(InStreamData);
                    DownloadFromStream(InStreamData,'','','',FileName);
                end;
            }
        }
    }
}

If you look at the above code it is taking required data from customer table and export the data in text file as below.

To get more insight of data type have a look at MS documentation from below link

https://docs.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/methods-auto/textbuilder/textbuilder-data-type

Hope this will help you.

Stay tuned for more.

Original Post https://ammolhsaallvi.blog/2022/04/18/how-to-export-data-using-textbuilder-in-business-central/

0 Votes: 0 Upvotes, 0 Downvotes (0 Points)

Leave a reply

Join Us
  • X Network2.1K
  • LinkedIn3.8k
  • Bluesky0.5K
Support The Site
Events
April 2025
MTWTFSS
  1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30     
« Mar   May »
Follow
Sign In/Sign Up Sidebar Search
Popular Now
Loading

Signing-in 3 seconds...

Signing-up 3 seconds...