• Home
  • About Me
  • Contact Me
  • Downloads
  • White Papers
  • Web Sites
  • Post List
  • Articles
  • FAQ

Olof Simren - Microsoft Dynamics 365 Business Central Blog

  • Home
  • About Me
  • Contact Me
  • Downloads
  • White Papers
  • Web Sites
  • Post List
  • Articles
  • FAQ

XML Buffer and CSV Buffer Tables

March 27, 2017 Posted by Olof Simren Development, Miscellaneous 17 Comments

Most of us that’s been programming in Dynamics NAV for a while are aware of the Excel Buffer table. It is a super useful table that can be used to create and read Excel files from C/AL code. This table have been around as far as I remember, and now it has some siblings, the XML Buffer and CSV Buffer tables.

The concept is the same, a table with functions to create or read files, this time XML/CSV files instead of Excel files. Just like with the Excel Buffer table, the XML buffer and CSV buffer table should be used as temporary tables.

This blog post describes how those tables can be used. With some examples where the task is to export/import items through XML/CSV files.

Create XML File using the XML Buffer Table

First the XML export; to do this I create a function in a codeunit that has the XML Buffer (table 1235) as a temporary variable. As a first step I use the ‘AddGroupElement’ function to add an ‘Items’ group element. Then to that element I add an attribute using the ‘AddAttribute’ function, the attribute contains the company name from which the data is exported. Below that I add the code to loop through the item records where I use the same functions to add an ‘Item’ group element with the item number as an attribute. To add child elements for the fields in the item table I use the ‘AddElement’ function and when I am done adding all the fields I use the ‘GetParent’ function to go back up one level in order to add the next item. Simple, right? If not, look at the code below and the screenshot of the file and it probably makes sense.

After the items have been looped through the ‘Save’ function will export the data and create an XML file with the given name and path (note that the XML Buffer table also have some functions to handle the upload and download of the file and to add namespace information, etc. I have skipped all that to keep it simple).

The file created then looks like below.

As easy as it gets to create an XML file with data from NAV. Almost too easy! 🙂

Import XML File using the XML Buffer Table

So, how does the import work using the XML Buffer table? It is as easy as the export. You create the table as a temporary variable and just use the function called ‘Load’ to load the XML file into the XML Buffer table. The records in this temporary table can then be processed as any other records. There are some predefined functions in the table to find the child notes, attributes, etc. but when I did this I found it easier just to go through the records in the table, something like below (which might not be the best written code but at least an example).

So that was quite easy as well.

Create CSV File using the CSV Buffer Table

For the CSV export I basically just create a new function that’s very similar to the one for the XML export; but instead of the XML Buffer as a temporary table variable I use the CSV Buffer table (table 1234, cool table number btw 🙂 ). The syntax is slightly different, you use the ‘InsertEntry’ function to add data by specifying the line number, field number and value. And then the ‘SaveData’ function to create the file. The ‘SaveData’ function is called with a file name and field separator, in the below example I use a comma as a field separator, I think something like a TAB is much better, but it seems like you will have to modify the CSV buffer table itself to get that.

The file created then looks like below.

Nice!

Import CSV File using the CSV Buffer Table

Importing data from a CSV file using the CSV buffer table is also very easy. You use the ‘LoadData’ function to import the data from the file into the temporary table. Note that in addition to the file name you also specify the field separator. Once the data is in the table you can process it, the table only have three fields; Line No., Field No., and Value. The code to import the data and then process it could look something like below.

Also nice and simple.

Buffer Tables vs. XML Ports

So, the question now is when to use those two tables instead to creating an XML Port. To me if it is a simple structure of the data that should be exported or imported and the amount of data is fairly low then I would probably use the buffer tables, as you can see above they are very easy to work with. If the export or import are more of a complicated nature I would probably use an XML Port, you just have some more configurable option with that. An XML Port will most likely also have better performance if you are handling large amount of data, this since the buffer tables created one record per field in a temporary table which is not a very sufficient way of doing it.

An XML Port also have the advantage of being able to be passed through a codeunit that’s exposed as a web service. So if that’s the requirement, the an XML Port would be the obvious choice.

Personally I think I will use the two buffer tables quite frequently and I think it is a nice addition to Dynamics NAV.

Feel free to share this post if you like it. Cheers! 🙂

Share this:

  • Share on Facebook (Opens in new window) Facebook
  • Share on X (Opens in new window) X

Related


Discover more from Olof Simren - Microsoft Dynamics 365 Business Central Blog

Subscribe to get the latest posts sent to your email.

Tags: Buffer TableCALCSVExcelFile ExportFile ImportXML
17 Comments
Share
15

About Olof Simren

I am a Microsoft Dynamics NAV and 365 Business Central Expert, I started implementing Microsoft Dynamics NAV in 2002, back then it was called Navision Attain. Throughout the years there has been many exciting implementations in different parts of the world, all of them with different challenges but with one common theme; manufacturing. As a consultant, I bring over 20 years of experience in implementing Microsoft Dynamics NAV and 365 Business Central within manufacturing and distribution companies. The services I offer includes project management, consultation, development and training. Feel free to contact me if you need help with anything related to Microsoft Dynamics NAV or 365 Business Central. I work through my company Naviona where I team up with other skilled Microsoft Dynamics NAV and 365 Business Central Experts.

You also might be interested in

C/AL Editor in Dynamics NAV 2016

Nov 25, 2015

The 2016 version of Microsoft Dynamics NAV comes with a[...]

Add Order Lines to Navigation Pane

Apr 7, 2014

From time to time I run into situations where users[...]

Write C/AL Code in Excel

Sep 22, 2014

This is something that I did some days ago and[...]

17 Comments

Leave your reply.
  • Antonio
    · Reply

    March 27, 2017 at 10:20 AM

    Welcome back Olof! I was missing your posts! Great one… as usual.

    • Olof Simren
      · Reply

      Author
      March 27, 2017 at 5:22 PM

      Thanks!
      Yeah, I have been busy with other things, I will try to get back to blogging more again.

      /Olof

  • Capone
    · Reply

    March 27, 2017 at 1:19 PM

    I wonder if that is a part of the strategy to eliminate dotnet code since Microsoft will in the long run stopp supporting dotnet interop.

  • Jeremy Vyska
    · Reply

    March 27, 2017 at 2:19 PM

    Great topic and thorough! Continued great thanks for your always helpful NAV posts.

  • Josep Pages
    · Reply

    April 10, 2017 at 3:17 AM

    Very usefull.

  • Dimitrios Babas
    · Reply

    April 18, 2017 at 1:23 PM

    That’s great. Thanks.

  • Martin
    · Reply

    January 8, 2018 at 5:48 AM

    Thank you 🙂 helped us a lot with importing XML document files 🙂

  • Job
    · Reply

    July 26, 2018 at 8:50 AM

    Hi,

    In case u use multiple AddGroupElement so you end up for example at level 8.. dont forget to perform a FINDSET on the TempXMLBuffer before exporting your xml.
    IF you ommit this FINDSET you end up with only a part of you TempXMLBuffer in your exported XML-file.

    SalesShipmentHeader.GET(SalesShipmentHeaderNo);
    TempXMLBuffer.AddGroupElement(‘SalesShipmentHeader’);
    TempXMLBuffer.AddAttribute(‘No’,SalesShipmentHeader.”No.”);
    TempXMLBuffer.AddAttribute(‘Sender’,COMPANYNAME);
    TempXMLBuffer.AddElement(‘Destination’,SalesShipmentHeader.”Sell-to Customer Name”);
    TempXMLBuffer.AddGroupElement(‘Details’);
    SalesShipmentLine.SETRANGE(“Document No.”,SalesShipmentHeaderNo);
    IF SalesShipmentLine.FINDSET THEN
    REPEAT
    TempXMLBuffer.AddGroupElement(‘Line’);
    TempXMLBuffer.AddAttribute(‘LineNo’,FORMAT(SalesShipmentLine.”Line No.”));
    TempXMLBuffer.AddElement(‘Type’,FORMAT(SalesShipmentLine.Type));
    TempXMLBuffer.AddElement(‘No’,SalesShipmentLine.”No.”);
    TempXMLBuffer.AddElement(‘Description’,SalesShipmentLine.Description);
    TempXMLBuffer.AddElement(‘Quantity’,FORMAT(SalesShipmentLine.Quantity));
    TempXMLBuffer.AddElement(‘Price’,FORMAT(SalesShipmentLine.”Unit Price”));
    TempXMLBuffer.GetParent;
    UNTIL SalesShipmentLine.NEXT = 0;

    //FINDSET Recordset to point to the first record before exporting…
    IF NOT TempXMLBuffer.FINDSET THEN
    EXIT;

    TempXMLBuffer.Save(‘C:\Temp\’ + SalesShipmentHeader.”No.” + ‘.xml’);
    IF GUIALLOWED THEN
    PAGE.RUNMODAL(PAGE::”Select Source”,TempXMLBuffer);

    Kind regards,
    Job

    • Muthuraj
      · Reply

      December 11, 2018 at 2:28 AM

      Hi Olof,
      That’s superrrr…

    • Muthuraj
      · Reply

      December 11, 2018 at 2:31 AM

      Hi JOB,
      Its really helpful. Before XML Buffer , DELETEALL line is missing.

      Regards,
      Muthuraj U

      • Job
        · Reply

        January 7, 2019 at 3:21 PM

        @Muturaj,
        Thanks for the feedback.
        I’ll add DELETEALL in the future 🙂

  • Henrik Frederiksen
    · Reply

    August 11, 2018 at 1:13 PM

    Saved my day!!
    XMLBuffer.Load – wauw…just did the trick – thanks to you, Olof!!!

    Big thanks!

    Cheers,

    Henrik

  • Nasir Mahmood
    · Reply

    January 20, 2020 at 10:45 AM

    Hi, thanks for the great post, but I have an issue at the end of code when I call function SAVE(); it gives me an error.
    ” The type or method ‘Save’ cannot be used for ‘Extension’ development.AL(AL0296) “.

    I couldn’t figure out what is this. Please help

  • Anders Nielsen
    · Reply

    May 15, 2020 at 2:54 AM

    Hi.

    Do you know if the Cloud version supports the XML Buffer functionality?

    Br Anders

    • Olof Simren
      · Reply

      Author
      June 5, 2020 at 7:55 AM

      Hi Anders,
      Yes it does, the XML Buffer table is there as well as the codeunits around it.

  • Georg LaBonte
    · Reply

    August 22, 2022 at 10:06 AM

    Hey,

    I’m running Navision 2013 – and I only see the XML Buffer table in our test environment- not in production environment. How do you add this table (1235) to your environment?

    Thanks

  • Jon
    · Reply

    August 1, 2023 at 1:06 PM

    One drawback I find with XMLPorts is when you run them from a Codeunit or Report inside a Job Queue. They lose their formatting and only export as XML. If you’re XMLPort is formatted to export as CSV it will not be a CSV if you run from a Job Queue. Is there a way around this?

Leave a Reply

Your email is safe with us.
Cancel Reply

Subscribe to My Blog via Email

Check Out Our Apps in AppSource

My Dynamics NAV Partner

Naviona, LLC

Categories

  • Assembly (3)
  • Development (35)
  • Finance (14)
  • General (28)
  • Inventory (24)
  • Manufacturing (36)
  • Miscellaneous (27)
  • Purchase (9)
  • Sales (11)
  • Warehouse (7)

Tags

.net Add-in AI AppSource Assembly Assembly BOM Business Central CAL Capacity Consumption Contact Copilot Costs Customer Development Dimensions Excel Finance Flushing General Ledger Inventory Item Item Tracking Low-Level Code MRP NAV 2015 NAV 2016 Output Planning Production Production BOM Production Orders Purchase Orders Receipts Reporting Reports Routing Sales Sales Order Stockkeeping Unit Subcontracting Task List Warehouse Warehouse Shipment Work Center

Recent Posts

  • Business Central Configuration Audit using Vibe Coding
  • Copilot in Planning Parameter Worksheet
  • Copilot in Planning Worksheet
  • Copilot Inventory Queries
  • Record Deletion Tool for Business Central in AppSource
  • Reopen Finished Production Orders
  • XML Buffer and CSV Buffer Tables
  • Functionality Improvements in NAV 2017
  • Reversing Production Output and Consumption
  • Return Merchandise Authorization (RMA)

Categories

  • Assembly
  • Development
  • Finance
  • General
  • Inventory
  • Manufacturing
  • Miscellaneous
  • Purchase
  • Sales
  • Warehouse

Contact Us

We're currently offline. Send us an email and we'll get back to you, asap.

Send Message

Categories

  • Assembly (3)
  • Development (35)
  • Finance (14)
  • General (28)
  • Inventory (24)
  • Manufacturing (36)
  • Miscellaneous (27)
  • Purchase (9)
  • Sales (11)
  • Warehouse (7)

Tags

.net Add-in AI AppSource Assembly Assembly BOM Business Central CAL Capacity Consumption Contact Copilot Costs Customer Development Dimensions Excel Finance Flushing General Ledger Inventory Item Item Tracking Low-Level Code MRP NAV 2015 NAV 2016 Output Planning Production Production BOM Production Orders Purchase Orders Receipts Reporting Reports Routing Sales Sales Order Stockkeeping Unit Subcontracting Task List Warehouse Warehouse Shipment Work Center

Recent Posts

  • Business Central Configuration Audit using Vibe Coding
  • Copilot in Planning Parameter Worksheet
  • Copilot in Planning Worksheet
  • Copilot Inventory Queries
  • Record Deletion Tool for Business Central in AppSource
  • Reopen Finished Production Orders
  • XML Buffer and CSV Buffer Tables
  • Functionality Improvements in NAV 2017
  • Reversing Production Output and Consumption
  • Return Merchandise Authorization (RMA)

Recent Comments

  • Olof on Business Central Configuration Audit using Vibe Coding
  • Andrew Trayfoot on Business Central Configuration Audit using Vibe Coding
  • Barrett Allen on Reopen Finished Production Orders
  • Kateryna on Business Central Configuration Audit using Vibe Coding
  • Takeshi Setoya on Reopen Finished Production Orders
  • Steve on Consignment Inventory
  • Olof Simren on Copilot in Planning Worksheet
  • Omaer Amjad on Copilot in Planning Worksheet

© 2026 · Olof Simren

  • Home
  • About Me
  • Contact Me
  • Downloads
  • White Papers
  • Web Sites
  • Post List
  • Articles
  • FAQ
Prev Next