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>
This commit is contained in:
Jesper Schulz-Wedde 2026-10-02 10:11:49 +02:00
parent 0867171b1a
commit 4e33ca87e2
5 changed files with 96 additions and 2 deletions

View file

@ -0,0 +1,34 @@
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;
}