web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :

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

Saurav.Dhyani Profile Picture Saurav.Dhyani 14,419 User Group Leader

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

This was originally posted here.

Comments

*This post is locked for comments