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
InventDimdefines the inventory dimensions to check.InventDimParmspecifies which dimensions should be used as filters.InventOnhandretrieves 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.

Like
Report
*This post is locked for comments