Maintain extension compatibility across versions

Completed

Publishing version 1 of an extension is the easy half of the lifecycle. Updating an extension that's already installed, with real data and possibly other extensions depending on it, requires you to plan the version, the schema change, and the migration code together before you publish anything.

Signal compatibility through the version number

Raise your extension's version in app.json for every release you intend other developers or tenants to distinguish from the last one. Other extensions that depend on yours declare a minimum version in their own manifest, so if you fix a defect or add a procedure that a dependent needs, raising your version lets that dependent's manifest require it explicitly:

{
  "id": "3f6e9c21-8a4d-4b7e-9c31-2d4f5a6b7c80",
  "name": "Contoso Risk Management",
  "version": "2.0.0.0",
  "application": "27.0.0.0"
}

A dependent extension that hasn't raised its own required version still installs against your new version, because a dependency's version field is a minimum, not an exact match. That's why removing or changing an existing public object or procedure, instead of adding alongside it, is the change most likely to break a dependent that never asked for your new version.

Business Central doesn't enforce semantic meaning for the four version parts. Document how your team uses them, such as reserving a major increment for breaking changes and a minor increment for compatible features, and apply that policy consistently.

Write upgrade code instead of relying on synchronize alone

Synchronizing a schema change updates the table structure, but it doesn't populate new fields with derived values or migrate data between old and new structures. For that, write an upgrade codeunit: a codeunit with Subtype = Upgrade whose system triggers run in a fixed order during the upgrade process:

codeunit 50110 "Contoso Risk Mgt Upgrade"
{
    Subtype = Upgrade;

    trigger OnUpgradePerCompany()
    var
        Customer: Record Customer;
    begin
        if Customer.FindSet(true) then
            repeat
                if Customer."Contoso Risk Rating" = Customer."Contoso Risk Rating"::" " then
                    Customer.Validate("Contoso Risk Rating", Customer."Contoso Risk Rating"::Unrated);
                Customer.Modify(true);
            until Customer.Next() = 0;
    end;

    trigger OnValidateUpgradePerCompany()
    var
        Customer: Record Customer;
    begin
        Customer.SetRange("Contoso Risk Rating", Customer."Contoso Risk Rating"::" ");
        if not Customer.IsEmpty() then
            Error(UpgradeIncompleteErr);
    end;
    var
    var
        UpgradeIncompleteErr: Label 'One or more customers still have an unset risk rating after upgrade.';
}

When present, the three trigger groups run in this order: OnCheckPreconditionsPerCompany verifies that the upgrade can safely proceed, OnUpgradePerCompany performs the data migration, and OnValidateUpgradePerCompany confirms the result. Each per-company trigger runs once for each company in its own system session. Per-database equivalents exist for data that isn't company-specific.

Use an upgrade tag when migration logic must run only once. The Upgrade Tag codeunit lets the upgrade check HasUpgradeTag before it changes data and call SetUpgradeTag after the change succeeds. Register the same tag for a first-time installation and for companies created later, so a future upgrade doesn't run historical migration logic against data that never needed it. Upgrade tags supplement validation checks; they don't replace checks that prevent overwriting populated replacement fields.

Deprecate instead of deleting

An object that another extension or tenant might still reference can't simply be deleted; doing so breaks anything that depends on it and blocks the new version from passing dependency checks. Instead, mark it obsolete and remove it in a later version, giving dependents time to migrate:

codeunit 50109 "Old Risk Calculator"
{
    ObsoleteState = Pending;
    ObsoleteReason = 'Replaced by codeunit 50102 Risk Rating Calculator, which adds historical trend support.';
    ObsoleteTag = '2.0';

    procedure CalculateRating(CustomerNo: Code[20]): Integer
    begin
        // Retained for backward compatibility.
    end;
}

ObsoleteState = Pending keeps the object's code and public surface in place while flagging it to developers. In a later version, once you're confident no supported dependent still calls it, change the state to Removed. Keep the obsolete object declaration in source so analyzers can verify the lifecycle and the compiler can report the removed symbol to dependents.

Test the upgrade path before you publish it

Before you publish a new version to an environment with real data, confirm on a copy or a test tenant that the schema synchronizes without data loss, the upgrade codeunit's precondition check passes, the migration produces the values you expect, and the validation trigger completes without raising an error. If any step fails, fix the upgrade code and retest rather than publishing and repairing data after the fact. Depending on the failure and available evidence, recovery can require a corrective migration or restoration from a verified pre-upgrade backup.

For the full trigger, tag, and administration sequence, see Upgrade extensions. For the compatibility lifecycle, see Obsolete objects, methods, and symbols.