Wednesday, 27 January 2016

Create record in inventdim table through code X++ in ax 2012

Hi ,

Today I am going to tell you how to create record in inventdim table through code.

In InventDim Table we cant use .insert() method for creating record.

As it is very important table and hit many transaction so it is recommended not to play with this table unless it is not necessary. may be it cause data in consistancy.

But as like me if you have to do with this table you can use below code at your own risk.

Its is working code for sure.

 ttsBegin;
        item = InventTable::find(ItemId);                  // Item id = "Item-0001"
        inventdim.InventSiteId          = Site;              // Site = "Site1"
        inventdim.InventLocationId      = Location;  // Location = "Location1"
        if(item.colorActive())
        {
            inventdim.InventColorId         = color;       // color = "Blue"
        }
        if(item.sizeActive())
        {
            inventdim.InventSizeId          = Size;           // Size = "Small"
        }
        if(item.configActive())
        {
            inventdim.configId              = config;
        }
        if(item.styleActive())
        {
            inventdim.InventStyleId         = style;          // Style = "Round" 
        }
        
        inventDim = InventDim::findOrCreate(inventDim);

ttsCommit;

------------------------------------------------------
hope it will help to resolve your issue

No comments:

Post a Comment