Skip to main content

Notifications

Community site session details

Community site session details

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

Need Help Retrieving Available Inventory & Gross Requirement per Location

(5) ShareShare
ReportReport
Posted on by 30

Hi,

 

I’m trying to retrieve two key values from Business Central:

Available Inventory (i.e. current stock by location)

Gross Requirement (i.e. qty. on sales order by location)

I can see these values on the Availability by Location page, but I’m unable to pick them correctly through a query or custom API

Can you please guide me on this?

 

Thanks!

 
  • Suggested answer
    Suresh Kulla Profile Picture
    47,789 on at
    Need Help Retrieving Available Inventory & Gross Requirement per Location
    What you have added to retrieve those values through API, if you can share the code we can suggest, you need to provide us more details. The fields are flowfields and some are calculated fields so you just need to copy over the same logic. 
     
     
  • Suggested answer
    Jainam M. Kothari Profile Picture
    7,938 on at
  • Suggested answer
    YUN ZHU Profile Picture
    83,301 Super User 2025 Season 1 on at
    Need Help Retrieving Available Inventory & Gross Requirement per Location
    If you need to view it in the API, this requires customization. You can refer to the standard logic on the Availability by Location page to obtain the data.
    PS: Remove ability to expose a Microsoft page as a OData endpoint (removal)
     
    Thanks.
    ZHU
  • Suggested answer
    Khushbu Rajvi. Profile Picture
    16,382 Super User 2025 Season 1 on at
    Need Help Retrieving Available Inventory & Gross Requirement per Location
  • Suggested answer
    Holly Huffman Profile Picture
    6,085 on at
    Need Help Retrieving Available Inventory & Gross Requirement per Location
    Good morning, afternoon, or evening depending on your location!
     
    To retrieve Available Inventory and Gross Requirement per location in Dynamics 365 Business Central, you can use a combination of queries and custom APIs. Here's how you can approach this:
     
    1. Using Queries in Business Central
    You can create a query object to fetch the required data from the relevant tables:
    • Tables to Use:
      • Item Ledger Entry: For current stock (Available Inventory).
      • Sales Line: For Gross Requirement (quantities on sales orders).
    • Steps:
      1. Create a new query object in AL.
      2. Add Item Ledger Entry and Sales Line as data items.
      3. Use filters to group data by Location Code.
      4. Calculate:
        • Available Inventory: Sum of Quantity in Item Ledger Entry.
        • Gross Requirement: Sum of Quantity in Sales Line.
          Example AL Code:
          query 50100 "Inventory and Requirement Query"
          {
               Caption = 'Inventory and Requirement Query';
               DataItem(ItemLedgerEntry; "Item Ledger Entry")
               {
                   Column(LocationCode; "Location Code") { }
                   Column(AvailableInventory; Sum("Quantity")) { }
               }
               DataItem(SalesLine; "Sales Line")
               {
                   DataItemLink = "Location Code" = FIELD("Location Code");
                   Column(GrossRequirement; Sum("Quantity")) { }
               }
          }
    2. Using Custom APIs
    If you need to expose this data via an API:
    • Steps:
      1. Create a new API page in AL.
      2. Use the query created above or directly fetch data from the tables.
      3. Add fields for Available Inventory and Gross Requirement.
        Example API Page:
        page 50101 "Inventory API"
        {
             PageType = API;
             SourceTable = "Item Ledger Entry";
             ApplicationArea = All;
             Layout
             {
                 Area(Content)
                 {
                     Field(LocationCode; "Location Code") { }
                     Field(AvailableInventory; Sum("Quantity")) { }
                     Field(GrossRequirement; Sum("Quantity")) { }
                 }
             }
        }
    3. Filtering and Optimizing 4. Alternative: Availability by Location Page
    If you only need to view the data, the Availability by Location page provides a built-in overview. However, for programmatic access, the above methods are more suitable.
     
    Hope this helps some!

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

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

🌸 Community Spring Festival 2025 Challenge Winners! 🌸

Congratulations to all our community participants!

Adis Hodzic – Community Spotlight

We are honored to recognize Adis Hodzic as our May 2025 Community…

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

#1
Sohail Ahmed Profile Picture

Sohail Ahmed 1,063

#2
YUN ZHU Profile Picture

YUN ZHU 1,002 Super User 2025 Season 1

#3
Mansi Soni Profile Picture

Mansi Soni 810

Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans