The Base App contains a code snippet within the Item Table Rename function that performs updates across related tables when an Item No. is changed. For instance, it ensures that Sales Lines associated with the renamed Item are appropriately updated.
// Base App - Item Table
trigger OnRename()
var
SalesLine: Record /Sales Line/;
begin
SalesLine.RenameNo(SalesLine.Type::Item, xRec./No./, /No./);
// Additional code follows, but kept concise for clarity.
end;
// The following customization is causing an issue:
trigger OnAfterRename()
begin
IntercompanyRename();
end;
procedure IntercompanyRename()
var
inventorySetup: Record /Inventory Setup/;
item: Record Item;
begin
InventorySetup.Get();
if inventorySetup./Source Company/ <> '' then begin
Item.ChangeCompany(inventorySetup./Source Company/);
if Item.GET(xRec./No./) then begin
item.Rename(Rec./No./); // THE ISSUE OCCURS HERE
end;
end;
end;
When working in Company /A/ and renaming an Item record (modifying the Item No.), the Base App's /OnRename/ code from Company /B/ seems to execute in Company /A/. This results in a situation where a record is renamed in Company /B/, but the related tables are not updated as expected. This behavior could potentially lead to inconsistencies in the database, such as Sales Lines referencing a non-existing Item No. I've observed this issue in Business Central version 17.17.
It is important to note that the /Source Company/ field will always be empty in Company /B,/ which should prevent unintended loops due this customization. We have double checked this.
So basically I want to confirm if: when I rename a record in one company, I try to rename a record in another company, will the OnRename trigger for the second company run in the first company?