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!!!




AX2012 : Understanding InventDimID

Hi Friends,
In this post I will describe my view of what is InventDimID and how we can use it in our solutions.

We know there are different inventory dimensions available in Microsoft Dynamics AX like Site, Warehouse, Location, Pallet, Batch number, Serial number etc. These can be active for an item based on the storage dimensions assigned on it.


Let us take an example, we have an Item "BRK6348" on which Site, Warehouse, Location, Pallet ID are active and we did an inventory transaction on this item say on Site '01', Warehouse 'Main', Location 'LOC001' and Pallet Id 'PLT001' and we want to design a table to store all these values on our custom transaction table.

A simple approach is to add fields for all the inventory dimensions in your table. Imagine if there are 10 inventory dimensions in system then we need to add 10 fields in our table and if we have 100 inventory transactions for this item on the set of these inventory dimension combination then we will storing same data in 100 records in all 10 fields. This will bloat the database size and also impact the performance of queries on this table.  A sample of such table would look like below:


Now to simplify this we create a new ID field which refers to a set of combination of these values. For example ID "10001" refers to  Site '01', Warehouse 'Main', Location 'LOC001' and Pallet Id 'PLT001'. We also create a separate table to store values of these 10 fields along with this ID field and add ID field in our transaction table. So in all 100 records we can store data in only one ID field.
We are not required to store data of 10 inventory dimensions fields 100 times, instead we just need to store value of 1 field in 100 records pointing to same combination of these inventory dimensions.  A sample of such tables with some records will look as below:


This ID in Dynamics AX is known as InventDimID and the table which stores all the combinations of inventory dimensions and there ID is InventDim:



This table plays very important role in AX. Any table which stores inventory dimensions in AX like salesLine, purchLine,inventTrans all have relation to inventDim table.




There are already functions to create and find inventDimID for a combination if inventory dimensions . Most commonly used is findOrCreate just initialize a blank instance of inventDim table object, assign all your inventory dimensions and then call this function to assign the inventDimID to your record. If a invnetDimID for the combination exists then system will return it else it'll create a new and return the inventDimId.


So if you are designing new tables in system to store inventory dimensions, then leverage this smart database architecture of AX and give your solution a smart design.