Skip to main content

How to Export CSV Files from Business Central Using CSV Buffer (Developer Guide)

Hi Readers,

In this article we will discuss regarding how to export data from business central in CSV Format.

CSV Export is built in feature of Business Central. 


Overview

This article explains how to export CSV files from Microsoft Dynamics 365 Business Central using the CSV Buffer table, including common problems developers face and the best practices to avoid them.

It is written for Business Central developers who need a reliable, integration-safe CSV export, not an Excel-based workaround.


What Problem Does This Solve?

Business Central customers often request “Excel export”, but in most real-world scenarios, the actual requirement is:

  • Data transfer to an external system

  • Import into another ERP, WMS, or reporting tool

  • Automation or scheduled data exchange

In these cases, CSV is the correct format, not Excel.


What Is CSV Buffer in Business Central?

CSV Buffer is a built-in table in Business Central (and legacy NAV) designed specifically for CSV file handling.

CSV Buffer Table Structure

FieldPurpose
Line No.Represents the row number
Field No.Represents the column number
ValueThe actual data value (Text, max 250 chars)

This structure allows developers to:

  • Control column order

  • Add headers explicitly

  • Apply formatting rules

  • Handle large datasets efficiently


Recommended CSV Export Architecture

A standard and scalable CSV export pattern looks like this:

  1. User clicks an Export CSV action

  2. Action calls a codeunit

  3. Codeunit:

    • Uses temporary CSV Buffer

    • Adds header row

    • Inserts data row by row

    • Writes content to a Blob

    • Downloads the file to the client

This pattern is upgrade-safe, testable, and performant.


Common CSV Export Issues (and Why They Happen)

Issue 1: Commas Break Columns

Problem:
Text fields like item descriptions contain commas, causing column shifts in Excel or external systems.

Cause:
CSV format treats commas as separators.

Solution:
Sanitize text values before inserting them into CSV Buffer (e.g., remove or replace commas).


Issue 2: Missing Headers

Problem:
CSV files without headers are unclear and error-prone.

Cause:
Developers skip header creation.

Solution:
Always insert headers using:

  • Field captions, or

  • Explicit column names


Issue 3: FlowFields Export as Zero

Problem:
Fields like Inventory show incorrect values.

Cause:
FlowFields are not calculated automatically.

Solution:
Use:

  • CalcFields

  • or SetAutoCalcFields


Performance Best Practices for Large Exports

When exporting large datasets:

  • Use SetLoadFields to fetch only required fields

  • Avoid unnecessary FlowField calculations

  • Keep CSV Buffer temporary

  • Do not load full records when not needed

These steps significantly reduce memory usage and execution time.


CSV Separator Clarification (Important)

Despite the name, CSV does not require commas.

You may use:

  • Semicolons (;)

  • Colons (:)

  • Pipes (|)

Excel and most tools can interpret custom separators using Text to Columns.

This is especially useful when:

  • Data frequently contains commas

  • CSV is consumed by non-Excel systems


Can CSV Buffer Be Used for Import?

Yes.

CSV Buffer supports:

  • Exporting CSV

  • Importing CSV

This makes it a versatile tool for two-way data exchange in Business Central.


When Should You NOT Use CSV Buffer?

Avoid CSV Buffer when:

  • The requirement is a formatted Excel report

  • Users need formulas, styling, or pivot tables

  • The output is purely for human analysis, not integration

In those cases, Excel-based approaches are more appropriate.


Summary 

Use CSV Buffer when:

  • Exporting structured data

  • Integrating with external systems

  • Performance and control matter

Avoid CSV Buffer when:

  • Excel formatting is required

Key Concepts:

  • CSV Buffer table

  • FlowFields and CalcFields

  • Data sanitization

  • Custom separators

  • Performance optimization


Note

This article is part of a Business Central data export series focused on real-world developer scenarios and best practices.

Watch the Full Video Tutorial


Want More Business Central Developer Content?

  • Subscribe to the YouTube channel

  • Join the Business Central developer community

  • Explore advanced AL, performance, and API topics


Regards,
Saurav Dhyani
MVP | NAVUG-AllStar | Edhate Consulting

Comments

Popular posts from this blog

Microsoft Dynamics NAV 2016 - How to Configure Phone Client.

Hi All, In this article we will discuss how we can connect Microsoft Dynamics NAV 2016 with New Client Launched i.e. Phone Client. This Article Contain Steps for a Android Phone as I have Only Android Phone. I am doing it having all tiers on my windows 8 machine, steps remain same for multiple servers but issues might be different. What we Need (Other what we discuss in this article) -  The Service Tier should be on Public IP . Some of the Data-card does not Provide you Public IP. check it for sure.

How to Set Up NavUserPassword Authentication in Business Central.

Hi Readers, In this article we will discuss steps to Setup NAVUserPassword in Business Central on-prem. NavUserPassword is an authentication method that's handled by Business Central Server, but isn't based on Windows users or Active Directory. Each user is set up with a username and password that's configured inside Business Central only. The user is prompted for username/password credentials when they start the client. #msdyn365bc, #credentialtype

Dynamics NAV - All that you need to know about MenuSuites.

Hi Readers, This article is based on a request from a blog reader who wanted to understand about MenuSuite in Dynamics NAV. If you have started working with Business central with AL Code then it does not apply to those releases but if you are interested go ahead. Let's start with Future - In Latest and greatest version of product MenuSuite are obsolete and no longer used. So this article applies if you want to learn about C/AL MenuSuite.