Find and Create Invent Dim record in AX 2012 [Using X++]


I know, it has been long time, as usual Clients will always keep us busy. Just wanted to share with you the how to create Inventory Dimension in AX 2012 using X++ Code

InventDimId createInventDim(ItemId                       _itemId,

                                   InventBatchId                _inventBatchId,

                                   WMSLocationId                _wmsLocationId,

                                   WMSPalletId                  _wmsPalletId,

                                   InventSerialId               _inventSerialId,

                                   InventLocationId             _inventLocationId,

                                   EcoResItemConfigurationName  _configId,

                                   EcoResItemSizeName           _inventSizeId,

                                   EcoResItemColorName          _inventColorId,

                                   InventSiteId                 _inventSiteId



    InventTable item = InventTable::find(_itemId);

    InventDim   inventDim;



    inventDim.InventBatchId     = _inventBatchId;

    inventDim.wmsLocationId     = _wmsLocationId;

    inventDim.wmsPalletId       = _wmsPalletId;

    inventDim.InventSerialId    = _inventSerialId;

    inventDim.InventLocationId  = _inventLocationId;




        inventDim.ConfigId          = _configId;




        inventDim.InventSizeId      = _inventSizeId;




        inventDim.InventColorId     = _inventColorId;


    inventDim.InventSiteId      = _inventSiteId;


    inventDim = InventDim::findOrCreate(inventDim);

    return inventDim.InventDimId;



Happy Dax6ng,

Sreenath Reddy

Sreenath Reddy


2 Responses to “Find and Create Invent Dim record in AX 2012 [Using X++]”

  1. Evgeny Glazov Says:


    Right, that’s better, because the method you’ve written has a number of potential flaws:

    1) The repetitive calls item.xxxActive() lead to repetitive queries to the same dim. group
    2) You check whether the item dimensions are active but you ignore the fact all the other dimensions may be set inactive
    3) You first set the site and then let the system initialize it again from the warehouse (every WH has a site assigned)
    4) You may also want the system initialize the default wms locations
    5) R2 comes with a number of additional storage and item dimensions
    5) Finally, in all my long AX praxis there have not been a case when you need an InventDim record built from scratch. There is usually a default InventDim to be specifically amended by a couple of inventory dimensions.

    Summary: your method may be considered an anti-pattern. 🙂


  2. Sreenath Reddy Says:

    Received comment on this and corrections, please note, this can be customized or improvized based on your requirements as this is just an example. There are many ways of doing it.I will writeup soon on this.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: