Skip to main content

Notifications

Announcements

No record found.

Small and medium business | Business Central, N...
Suggested answer

Switch Companies in AL And Append to a Table

(1) 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;
}
  • Suggested answer
    YUN ZHU Profile Picture
    YUN ZHU 74,115 Super User 2024 Season 2 on at
    Switch Companies in AL And Append to a Table
    Hi, hope the following helps.
    Collect data from different companies and Drilldown into the data of another company
     
    Thanks.
    ZHU

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Verified Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,391 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,445 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans