bcquality/microsoft/knowledge/upgrade/no-changecompany-in-upgrade.good.al
Jesper Schulz-Wedde 4e33ca87e2 knowledge(upgrade): upgrade code must not use ChangeCompany
Addresses ADO bug 651092. Upgrade and feature data update code must run in the
context of the company being upgraded; ChangeCompany leaves triggers, events and
upgrade tags in the calling company and races the target company's own upgrade.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
2026-10-02 10:11:49 +02:00

34 lines
1.1 KiB
AL

codeunit 50260 "Upgrade Current Company"
{
Subtype = Upgrade;
// The platform runs this trigger once per company, in that company's own session.
trigger OnUpgradePerCompany()
begin
UpgradeShippingAgentCodes();
end;
local procedure UpgradeShippingAgentCodes()
var
SalesOrderExt: Record "Sales Order Ext";
UpgradeTag: Codeunit "Upgrade Tag";
begin
if UpgradeTag.HasUpgradeTag(ShippingAgentUpgradeTag()) then
exit;
// Only the current company's rows; triggers, events, and the tag all apply here.
SalesOrderExt.SetRange("Shipping Agent Code", '');
if SalesOrderExt.FindSet(true) then
repeat
SalesOrderExt.Validate("Shipping Agent Code", SalesOrderExt."Legacy Carrier Code");
SalesOrderExt.Modify(true);
until SalesOrderExt.Next() = 0;
UpgradeTag.SetUpgradeTag(ShippingAgentUpgradeTag());
end;
local procedure ShippingAgentUpgradeTag(): Code[250]
begin
exit('CONTOSO-1001-ShippingAgentCode-20260101');
end;
}