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...
Suggested Answer

Need Help Retrieving Available Inventory & Gross Requirement per Location

(4) 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!

 
I have the same question (0)
  • Suggested answer
    Holly Huffman Profile Picture
    6,528 Super User 2025 Season 2 on at
    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!
  • Suggested answer
    Khushbu Rajvi. Profile Picture
    20,234 Super User 2025 Season 2 on at
  • Suggested answer
    YUN ZHU Profile Picture
    95,311 Super User 2025 Season 2 on at
    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
    Jainam M. Kothari Profile Picture
    15,627 Super User 2025 Season 2 on at
  • Suggested answer
    Suresh Kulla Profile Picture
    50,241 Super User 2025 Season 2 on at
    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. 
     
     

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 3,177

#2
Jainam M. Kothari Profile Picture

Jainam M. Kothari 2,467 Super User 2025 Season 2

#3
YUN ZHU Profile Picture

YUN ZHU 1,435 Super User 2025 Season 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans