Download our free white paper on Copilot in Microsoft Business Central! Download Now

Developing Extensions in Business Central Using VS Code

Kery Nguyen
By Kery Nguyen

2023-12-15

Before diving into the technical setup, here's what you should know about BC extensions:

They're not "customizations" in the traditional sense. Unlike older Dynamics NAV modifications where you changed the base code, BC extensions layer on top of the standard system. Think of them as add-ons rather than modifications.

They survive upgrades. This is huge. When Microsoft releases a new version of Business Central, your extensions typically continue working. No more dreading upgrade projects.

You don't need to be a programming wizard. While coding experience helps, I've seen accountants with basic Excel skills learn to build simple but useful extensions.

The learning resources are... scattered. Microsoft's documentation is improving but still leaves many practical questions unanswered. Community forums and blogs fill the gaps.

Setting Up Your Development Environment: The Practical Way

Let's skip the fluff and get your environment ready for actual development:

1. The Essential Tools

You'll need:

  • Visual Studio Code - The editor where you'll write code
  • AL Language extension - Teaches VS Code to understand AL
  • A Docker container OR a Business Central sandbox - Your testing environment

I recommend starting with a sandbox—it's easier to set up, and you won't need to mess with Docker configuration right away.

2. Getting Visual Studio Code Ready

  1. Download and install VS Code from code.visualstudio.com
  2. Open VS Code
  3. Press Ctrl+Shift+X (or click the Extensions icon in the sidebar)
  4. Search for "AL Language"
  5. Install the official Microsoft AL Language extension

Pro tip: Also install these non-essential but incredibly helpful extensions:

  • AL Object Designer
  • AL Variable Helper
  • CRS AL Language Extension

3. Getting a Business Central Sandbox

Microsoft provides free 30-day sandboxes for development:

  1. Go to businesscentral.dynamics.com
  2. Sign in with a Microsoft account (create one if needed)
  3. Choose "Try for free"
  4. Follow the prompts to create a sandbox

The secret step nobody mentions: Once your sandbox is running, you'll need to get the server URL to connect from VS Code:

  1. In your sandbox, click the gear icon (Settings)
  2. Click "Help & Support"
  3. Click "Service Information"
  4. Copy the "OData URL" up to ".com" (e.g., https://businesscentral.dynamics.com)
  5. You'll need this later when connecting VS Code

Creating Your First Extension: A Practical Example

Let's build something actually useful—a page extension that adds a customer's total sales to the customer card. Here's the step-by-step process:

1. Initialize Your Project

  1. Open VS Code
  2. Press Ctrl+Shift+P to open the command palette
  3. Type "AL: Go!" and press Enter
  4. Select "Create new project"
  5. Choose a folder on your computer
  6. VS Code will create a new AL project with some files

2. Configure Your app.json

The app.json file contains your extension's metadata. Edit it to look something like this:

{
    "id": "5d4f9c60-53c3-4e98-9c0f-ac3df063c1ad",
    "name": "Customer Sales Info",
    "publisher": "Your Company Name",
    "version": "1.0.0.0",
    "brief": "Shows total sales on customer card",
    "description": "This extension adds total sales information to the customer card",
    "privacyStatement": "",
    "EULA": "",
    "help": "",
    "url": "",
    "logo": "",
    "dependencies": [],
    "screenshots": [],
    "platform": "1.0.0.0",
    "application": "21.0.0.0",
    "idRanges": [
        {
            "from": 50100,
            "to": 50149
        }
    ],
    "resourceExposurePolicy": {
        "allowDebugging": true,
        "allowDownloadingSource": false,
        "includeSourceInSymbolFile": false
    },
    "runtime": "10.0",
    "features": [
        "NoImplicitWith"
    ]
}

The parts that really matter:

  • id: A unique GUID (VS Code generates this for you)
  • publisher: Your company name
  • application: The Business Central version you're targeting
  • idRanges: The range of IDs your objects will use

3. Connect to Your Sandbox

  1. Press Ctrl+Shift+P
  2. Type "AL: Download Symbols" and press Enter
  3. Select "Cloud Sandbox"
  4. Enter the OData URL you copied earlier
  5. VS Code will connect and download the symbols (object definitions) from Business Central

4. Create Your Extension Code

Create a new file called CustomerCardExt.al and add this code:

pageextension 50101 "Customer Card Ext" extends "Customer Card"
{
    layout
    {
        addafter(Name)
        {
            field("Total Sales"; Rec.GetTotalSalesLCY())
            {
                ApplicationArea = All;
                Caption = 'Total Sales (LCY)';
                ToolTip = 'Shows the total sales for this customer.';
                Editable = false;
            }
        }
    }
}

Next, create another file called CustomerTotalSales.al with this code:

codeunit 50101 "Customer Total Sales"
{
    procedure GetTotalSalesLCY(CustomerNo: Code[20]): Decimal
    var
        SalesInvoiceLine: Record "Sales Invoice Line";
        TotalAmount: Decimal;
    begin
        SalesInvoiceLine.SetRange("Sell-to Customer No.", CustomerNo);
        SalesInvoiceLine.SetFilter("Type", '%1|%2', SalesInvoiceLine.Type::Item, SalesInvoiceLine.Type::Resource);
        
        if SalesInvoiceLine.FindSet() then
            repeat
                TotalAmount += SalesInvoiceLine."Amount Including VAT";
            until SalesInvoiceLine.Next() = 0;
            
        exit(TotalAmount);
    end;
}

Finally, add a table extension to add this method to the Customer table. Create CustomerExt.al:

tableextension 50101 "Customer Ext" extends Customer
{
    procedure GetTotalSalesLCY(): Decimal
    var
        CustomerTotalSales: Codeunit "Customer Total Sales";
    begin
        exit(CustomerTotalSales.GetTotalSalesLCY(Rec."No."));
    end;
}

5. Deploy and Test Your Extension

  1. Press F5 (or select Debug > Start Debugging)
  2. VS Code will compile your code and publish it to your sandbox
  3. Your browser will open with Business Central
  4. Navigate to a customer card to see your new field showing total sales

What just happened? You extended the Customer Card page to show a new field, added a method to the Customer table to calculate total sales, and created a codeunit to handle the calculation logic.

Beyond the Basics: What I Learned the Hard Way

After creating dozens of extensions, here are the lessons that took me months to discover:

1. Structure Your Extensions Properly

Don't put all your code in one file or even one extension. Create separate extensions for different functional areas:

  • Core extension for fields and basic functionality
  • Integration extensions for connecting to other systems
  • UI extensions for report and page modifications

This makes maintenance much easier and allows you to update parts independently.

2. Use Events, Don't Fight Them

Business Central is built on an event-driven architecture. Learn to:

  • Subscribe to the right events (pre vs. post, validate vs. modify)
  • Create your own events for extension points
  • Debug using event recorder to see what's firing
// Example of subscribing to an event
[EventSubscriber(ObjectType::Codeunit, Codeunit::"Sales-Post", 'OnAfterPostSalesDoc', '', false, false)]
local procedure OnAfterPostSalesDoc(var SalesHeader: Record "Sales Header")
begin
    // Your code here runs after a sales document is posted
    CreateCustomNotification(SalesHeader);
end;

3. Performance Matters More Than You Think

My first extensions were painfully slow. I learned to:

  • Avoid nested loops
  • Use SETRANGE/SETFILTER before FIND operations
  • Cache results when appropriate
  • Use temporary records for processing
// Bad performance
foreach Customer in Customers do
    foreach SalesLine in AllSalesLines do
        if SalesLine."Sell-to Customer No." = Customer."No." then
            // Do something

// Better performance
foreach Customer in Customers do begin
    SalesLines.SetRange("Sell-to Customer No.", Customer."No.");
    if SalesLines.FindSet() then
        repeat
            // Do something
        until SalesLines.Next() = 0;
end;

4. Debugging Will Save Your Sanity

Learn these debugging techniques early:

  • Set breakpoints in VS Code (F9)
  • Use Message() to see values (but remove before production)
  • Check for field validation errors in OnValidate triggers
  • Use the Event Recorder to understand execution flow

5. Version Control Is Not Optional

Even for solo developers, use Git:

  • Commit small, logical changes
  • Write meaningful commit messages
  • Use branches for features and fixes
  • Consider GitHub or Azure DevOps for repository hosting

The Resources That Actually Helped Me Learn

After wading through countless documentation pages and videos, these resources genuinely helped me improve:

  1. Microsoft Learn's Business Central Development Path - Good for structured learning

  2. Dynamics NAV / Business Central User Group (DUG) - The forum at dynamicsuser.net/bc has saved me countless hours

  3. James Crowter's "Implementing Microsoft Dynamics 365 Business Central On-Premise" - Despite the title, it's excellent for cloud development too

  4. Waldo's Blog - waldo.be has practical advice from a veteran BC developer

  5. Kamil Sacek's AL Code Samples - github.com/kine/AL-Code-Samples shows real-world examples

Common Mistakes to Avoid (I Made Them All)

  1. Trying to port C/AL code directly to AL - The architecture is different; embrace extensions rather than fighting them

  2. Ignoring Microsoft's application designs - Follow the patterns in the base application; they're there for a reason

  3. Not testing with enough data - An extension that works with 10 records might fail with 10,000

  4. Hardcoding business logic - Use setup tables to make your extensions configurable

  5. Forgetting about permissions - Users need the right permissions to use your new functionality

Final Thoughts: Building Your Extension Development Skills

Four years into my BC development journey, I'm still learning new techniques. The platform evolves rapidly, and each project brings new challenges.

If you're just starting, focus on:

  1. Understanding the Business Central data model
  2. Learning how events work
  3. Building small, focused extensions
  4. Reading others' code when possible
  5. Participating in community forums

Remember that every BC developer started where you are now. The learning curve might feel steep at first, but the ability to create custom functionality that perfectly fits your business needs makes it worthwhile.

Even better, the skills you develop are increasingly valuable as more companies adopt Business Central and need developers who can extend it to meet their specific requirements.

Business CentralExtensionsVS CodeAL LanguageSoftware Development
Choosing the right ERP consulting partner can make all the difference. At BusinessCentralNav, we combine deep industry insight with hands-on Microsoft Business Central expertise to help you simplify operations, improve visibility, and drive growth. Our approach is rooted in collaboration, transparency, and a genuine commitment to delivering real business value—every step of the way.

Let`'s talk

Explore Business Central Posts

image

Tips for Debugging in Business Central Effectively

Explore insightful debugging techniques tailored for Business Central developers, aimed at improving code quality and streamlining business operations.

By

Kery Nguyen

Date

2024-05-22

image

Must-Follow Blogs and Forums for Business Central

Get a deeper understanding of the landscape of blogs and communities for navigating Microsoft Dynamics 365 Business Central. Discover where to find precious resources, expert advice, and peer support.

By

Kery Nguyen

Date

2024-03-10

image

Data Cleanup Tips Before Migrating to Business Central

Learn how to efficiently prepare your data for migration to Microsoft Dynamics 365 Business Central with these expert data cleanup strategies.

By

Matias Orlando

Date

2024-01-15