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

Notifications

Announcements

No record found.

Community site session details

Community site session details

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

Fill up custom temporary table with item ledger entry table data

(5) ShareShare
ReportReport
Posted on by 281
Hello, I have created a custom table which is of type temporary, it has fields item no., description, location, available qty on hands for that location. I want to fill up this with item ledger entry table data in this temporary table's page.when I open the page, I want to see the data, so please suggest me code for this one. 
I have the same question (0)
  • Verified answer
    Ramesh Kumar Profile Picture
    7,529 Super User 2025 Season 2 on at
    Temporary table page to show item availability per location. You can achieve this by using AL code in the OnOpenPage or OnAfterGetRecord trigger of the Page to populate your temporary table from the Item Ledger Entry table.
     
    trigger OnOpenPage()
    var
        ItemLedgerEntry: Record "Item Ledger Entry";
        TempAvailability: Record TempItemAvailability temporary;
        Item: Record Item;
    begin
        // Loop through all Item Ledger Entries
        ItemLedgerEntry.SetRange("Entry Type", ItemLedgerEntry."Entry Type"::"Positive Adjmt.");
        if ItemLedgerEntry.FindSet() then
            repeat
                // Look for existing combination of Item No. + Location Code
                if not TempAvailability.Get(ItemLedgerEntry."Item No.", ItemLedgerEntry."Location Code") then begin
                    TempAvailability.Init();
                    TempAvailability."Item No." := ItemLedgerEntry."Item No.";
                    TempAvailability."Location Code" := ItemLedgerEntry."Location Code";
                    
                    // Optional: pull item description
                    if Item.Get(ItemLedgerEntry."Item No.") then
                        TempAvailability.Description := Item.Description;
                    
                    TempAvailability."Available Quantity" := 0;
                end;
    
                // Add to available quantity
                TempAvailability."Available Quantity" += ItemLedgerEntry."Remaining Quantity";
    
                TempAvailability.Insert(true); // Use Insert(true) for temp record
            until ItemLedgerEntry.Next() = 0;
    end;
    
     

    Thanks
    Ramesh
     
     
  • Verified answer
    Tech-Lucky Profile Picture
    1,267 Super User 2025 Season 2 on at

    As suggested by Ramesh, this is the appropriate trigger to write the code in. However, I would recommend using Rec to insert the data instead of the TempAvailability variable. This is because if you use a separate temporary record variable, you won't be able to bind it to the page as a data source, and the data won't be displayed. Using Rec ensures that the page recognizes and displays the data correctly.

     
  • Suggested answer
    YUN ZHU Profile Picture
    95,748 Super User 2025 Season 2 on at
    Personally, I think using Query may have better performance.
    Dynamics 365 Business Central: How to make a query searchable (Add Query to Tell me)
    Dynamics 365 Business Central: Using the query as a data source for a page (Query.Open Method)
     
    Hope this helps.
    Thanks.
    ZHU
  • Verified answer
    CU22100733-0 Profile Picture
    281 on at
    Thanks @Ramesh Kumar  & @Tech-Lucky  for the suggestions--- I modifies and used the procedure on open page--
    Procedure Getiledata()
        var
            ile: Record "Item Ledger Entry";
        begin
            ile.Reset();
            ile.SetRange("Entry Type", ile."Entry Type"::"Positive Adjmt.");
            ile.Setfilter("Remaining Quantity", '<>%1', 0);
            if ile.FindSet() then
                // Look for existing combination of Item No. + Location Code
                Rec.Reset();
            Rec.SetRange("Item No.", ile."Item No.");
            Rec.SetRange("Location Code", ile."Location Code");
            if Rec.FindFirst() then begin
                Rec."Stock Available" += ile."Remaining Quantity";
                Rec.Modify();
            end else
                if not Rec.FindFirst() then begin
                    repeat
                        Rec.Init();
                        Rec."Entry No." := GetNextEntryNo();
                        Rec.Validate("Item No.", ile."Item No.");
                        Rec."Location Code" := ile."Location Code";
                        Rec."Stock Available" := 0;
                        Rec."Stock Available" += ile."Remaining Quantity"; // Add to available quantity
                        Rec.Insert(false);
                    until ile.Next() = 0;
                end;
        end;
  • CU22100733-0 Profile Picture
    281 on at
  • Suggested answer
    Khushbu Rajvi. Profile Picture
    20,647 Super User 2025 Season 2 on at

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

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

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 2,066

#2
YUN ZHU Profile Picture

YUN ZHU 658 Super User 2025 Season 2

#3
Sumit Singh Profile Picture

Sumit Singh 595

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans