Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics 365 | Integration, Dataverse...
Unanswered

Switch Companies in AL And Append to a Table

(0) ShareShare
ReportReport
Posted on by 4
I am trying to create a table in my AL code and BC which displays the entire inventory of one of my companies, it shows various records regarding each inventory item. However, I have multiple companies and want to display the inventory of all the companies.
 
In the code I am able to switch companies and able to display what company I am on, but I am unsure on how to append new items to the existing table which belongs to the other companies. So far, the inventory only displays all the products from Company 1, however I need to append all the items in Company 2's inventory and show it all in one table.
 
page 60100 BIRemainingItemQuantity
{
    ApplicationArea = All;
    Caption = 'Remaining Item Quantity';
    PageType = List;
    SourceTable = /Item Ledger Entry/;
    Permissions = tabledata /Item Ledger Entry/ = R;
    DataCaptionFields = /Entry No./;
    UsageCategory = History;
    DeleteAllowed = false;
    ModifyAllowed = false;
    InsertAllowed = false;
 
    layout
    {
        area(content)
        {
            repeater(General)
            {
                //Company name variable will be extracted from a third party Company object
                field(/Entity/; CompanyName)
                {
                    ApplicationArea = All;
                    ToolTip = 'Specifies the Company/Entity in which the item belongs to.';
                }
 
                field(/Item No./; Rec./Item No./)
                {
                    ApplicationArea = All;
                    ToolTip = 'Specifies the item number or UID for that item.';
                }
 
                field(/Location Code/; Rec./Location Code/)
                {
                    ApplicationArea = All;
                    ToolTip = 'Specifies the code for the location that the entry is linked to.';
                }
 
                field(/Variant Code/; Rec./Variant Code/)
                {
                    ApplicationArea = All;
                    ToolTip = 'Specifies the Variant Code.';
                }
 
                field(/Remaining Quantity/; Rec./Remaining Quantity/)
                {
                    ApplicationArea = All;
                    ToolTip = 'Specifies the quantity in the Quantity field that remains to be processed.';
                }
            }
        }
    }
 
    trigger OnOpenPage();
    var
        //Fetch company record
        Company: Record /Company Information/;
        //Define company name variable
        CompanyName: Text;
    begin
        Rec.SetFilter(/Remaining Quantity/, '<>%1', 0);
        if Company.Get() then
            Message('Current Company /%1/', Company.Name);
        Company.ChangeCompany('Company 2');
        //Add extra records.....
        //Switch Again
        Rec.ChangeCompany('Company 1');
        if Company.Get() then
            Message('Switched To/%1/', Company.Name);
 
       
    end;
 
    trigger OnAfterGetRecord()
    //On Each Record, Embed a new field which displays the company name
    var
        //Fetch company record
        Company: Record /Company Information/;
        //Define company name variable
        CompanyName: Text;
    begin
        //Assign the CompanyName variable to the Company Name which is fetched from the Company object
        if Company.Get() then
            CompanyName := Company.Name;
    end;
}
  • Leah Ju Profile Picture
    Microsoft Employee on at
    Switch Companies in AL And Append to a Table
    Hi partner,
    Based on your description, perhaps you should post in the following forum to wield better help:

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

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Kudos to the February Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 293,272 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,931 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156 Moderator

Leaderboard

Product updates

Dynamics 365 release plans