web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Small and medium business | Business Central, N...
Suggested Answer

ChangeCompany and RENAME record

(0) ShareShare
ReportReport
Posted on by
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?
 
 
  • Suggested answer
    IB-29041624-0 Profile Picture
    1,191 Moderator on at
    No, the trigger will only run in the company that is in the scope of your record variable.
    But I think it is good practise to complete processing in one company before you move on to the next company.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the August Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Small and medium business | Business Central, NAV, RMS

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 727 Super User 2026 Season 2

#2
YUN ZHU Profile Picture

YUN ZHU 512 Super User 2026 Season 2

#3
Grigorios Mavrogeorgis Profile Picture

Grigorios Mavrogeorgis 321 Super User 2026 Season 2

Last 30 days Overall leaderboard

Featured topics

Microsoft Training Manuals

Product updates

Dynamics 365 release plans