Friday 22 March 2013

AX2012: X++ code to get on hand on an item

Hi Friends,
In this post I would like to share a small piece of code using which we can get oh hand values for an item. Before jumping to it I would first like to share some basic information related to on hand information.
What do we need to know when we have to calculate on hand of an item?
Let us take the below example:
A company has one site , two warehouses , each warehouse has four locations and each location has two pallets. Each pallet is having 10 Pcs of an Item "CAB001" . I have illustrated the view in the below diagram:


Now if someone ask you what is the on hand of item "CAB001" you might respond back with a question : Where, in warehouse WH001 or in WH001 - Loc001 or in WH002-Loc003-P5 ??
The person will elaborate the question again: What is on hand of item "CAB001" in Warehouse WH001-Loc 003? And then you can easily say that the on hand is 20 Pcs. So let's try to see on hand values of our sample item in some different cases:
Site S001 --> 160 Pcs
Site S001, Warehouse WH001 --> 80 Pcs
Site S001, Warehouse WH002 - Loc002 --> 20 Pcs
Site S001, Warehosue WH002 - Loc004 - P7 --> 10 Pcs

So you will notice that on hand value changes with reference to the combination of inventory dimensions i.e. InventDimID against which we need to calculate the on hand of an Item. In my previous post (understanding-inventdimid ) I have explained how an InventDimID refers to a combination of Inventory Dimensions.

So now we know that in order to calculate on hand of an item we also need to know the inventory Dimensions against which we need to calculate it.
Another thing which we need to know is what on hand value we want to calculate. If you look at on hand screen you can see that on hands are calculated with respect to various business meanings:


AX out of the box provides us with classes to calculate on hand values . We can use InventOnHand class to calculate the required on hand values, below is a sample job to calculate available physical qty of the item D0001 (as shown in above image) in site 1, WH 13:


Result and mapping shown below:



InventOnHand class has other functions as well to return different qty , sample shown below:
We can also point to inventSum table object from invnetOnHand Class as get access to other on hand
values as shown below:

 Use InventOnHand class and simplify your on hand calculations.
Thanks!!!




9 comments:

  1. Nice blog, Code looks simple and understand easily. Actually it solves my confusion on getting "On hand inventory" based on product dimensions.

    ReplyDelete
  2. Hi Friend,
    How can I get the price value depend upon the variant?
    Exampe: I have one product called "AAA", I have 2 variance(Color, Size).
    In inventory "AAA" product have 10 quantity.
    1). AAA - size 10, color Black - 5 quantity
    2). AAA - size 12, color White - 5 quantity
    Friend, how can I get the value for that variance 1, 2 through X++.

    ReplyDelete
  3. Really helped me a lot.. :)

    ReplyDelete
  4. Hi Priyanka,

    I want inventory on hand of for each location.

    Can you please provide a solution for the above problem.

    Regards

    ReplyDelete
  5. If you're not able to access the InventDimId link:

    https://community.dynamics.com/365/financeandoperations/b/dynamicsofax/posts/ax2012-understanding-inventdimid

    ReplyDelete
  6. Beautifully presented and clearly explained

    ReplyDelete