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

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :

Check Stock Availability for Reservation in D365FO

dasdasd Profile Picture dasdasd 841

In D365FO, before reserving inventory, you may need to verify whether the required quantity is actually available for reservation.

The following X++ method checks stock availability based on the Item, Warehouse, WMS Location, and Batch dimensions. It uses the standard InventOnhand framework to retrieve the available physical and ordered quantities.

The method then adds these quantities together and compares the result with the requested quantity. It returns true when sufficient stock is available; otherwise, it returns `false.

public static boolean isStockAvailableToReserve(
    ItemId          _itemId,
    InventLocationId _inventLocationId,
    WMSLocationId   _wmsLocationId,
    InventBatchId   _inventBatchId,
    Qty             _qty)
{
    InventDim       inventDim;
    InventDimParm   inventDimParm;
    InventOnhand    inventOnHand;

    inventDim.InventLocationId = _inventLocationId;
    inventDim.wMSLocationId    = _wmsLocationId;
    inventDim.InventBatchId    = _inventBatchId;

    inventDimParm.InventLocationIdFlag = true;
    inventDimParm.wMSLocationIdFlag    = true;
    inventDimParm.InventBatchIdFlag    = true;

    inventOnHand = InventOnhand::newParameters(
        _itemId,
        inventDim,
        inventDimParm);

    return (inventOnHand.availPhysical() +
            inventOnHand.availOrdered()) >= _qty;
}

How It Works

  • InventDim defines the inventory dimensions to check.
  • InventDimParm specifies which dimensions should be used as filters.
  • InventOnhand retrieves the inventory availability for the specified item and dimensions.
  • availPhysical() returns the currently available physical inventory.
  • availOrdered() returns the available ordered/expected quantity.
  • The method compares the combined available quantity with the requested quantity and returns a Boolean result.

This provides a simple reusable method that can be called before performing an inventory reservation in D365FO.


This was originally posted here.

Comments

*This post is locked for comments