Release products to the legal entities using X++ [Dynamics AX 2012]

Friends,

In this post, I would like to share X++ Code that will help to release products to the legal entities from product master.

In Microsoft Dynamics AX 2012, Microsoft has enhanced the item-product data management framework to provide flexibility and sustainability across the organization.In Microsoft Dynamics AX 2012, all product master data is shared across all companies, and the virtual table collection concept is no longer available for product master data management. The old item representation (InventTable) still exists[msdn]

I will be using 2 legal entities – CEU and newly created legal entity ‘RAX’
[If you want to create new legal entity – Organization administration >> setup >> Organization >> Legal entities >> New]

Let me show you the product master data [a particular product] which I am trying to release using code.

EcoResProductReleaseManagerBase class will help to release products to the legal entities. static method -releaseproduct will release products.

static void SR_ReleaseProducts(Args _args)
{
EcoResProduct ecoResProduct;
;

select firstOnly ecoResProduct where EcoResProduct.DisplayProductNumber == “20003”; //Audio system
EcoResProductReleaseManagerBase::releaseProduct(ecoResProduct.RecId,
CompanyInfo::findDataArea(‘RAX’).RecId);
}

After running the above job, you will see that 20003 product number has been released to legal entity ‘RAX’ as shown below.

I know most of us are very familiar of creating items using code in AX 2009. Now, let me walk through with the equavalent code in AX 2012 [Hope I got it right, please note: This code is an attempt to findout the way it is in AX 2012. Request to test the code in dev environments before using them in live]

static void SR_ReleaseProducts_detailed(Args _args)
{
EcoResProduct ecoResProduct;
InventTable inventTable;
InventTableModule inventTableModule;
NumberSequenceTable numberSequenceTable;
ItemId itemId;
InventItemSetupSupplyType inventItemSetupSupplyType;

EcoResStorageDimensionGroupProduct ecoResStorageDimensionGroupProduct;
EcoResTrackingDimensionGroupProduct ecoResTrackingDimensionGroupProduct;
EcoResStorageDimensionGroupItem ecoResStorageDimensionGroupItem;
EcoResTrackingDimensionGroupItem ecoResTrackingDimensionGroupItem;
;

select firstOnly ecoResProduct where EcoResProduct.DisplayProductNumber == “20003”; //Audio system

changecompany (‘RAX’)
{
ttsBegin;
inventTable = null;
inventTableModule = null;
inventItemSetupSupplyType = null;
ecoResStorageDimensionGroupProduct = null;
ecoResTrackingDimensionGroupProduct = null;
ecoResStorageDimensionGroupItem = null;
ecoResTrackingDimensionGroupItem = null;

numberSequenceTable = InventParameters::numRefItemId().numberSequenceTable();
//get item id from:
//1. Product number if number seq for item ID is not set up or manual or return blank value
if (!numberSequenceTable.RecId || numberSequenceTable.Manual)
{
itemId = ecoResProduct.productNumber();
}
else //number sequence auto, get a number
{
itemId = NumberSeq::newGetNumFromId(numberSequenceTable.RecId).num();
}

inventTable.initValue();
inventTable.initFromEcoResProduct(ecoResProduct);
inventTable.ItemId = ItemId;
inventTable.NameAlias = ecoResProduct.SearchName;
inventTable.insert(true);

// Create inventTableModules

inventTableModule.initValue();
inventTableModule.ItemId = inventTable.ItemId;
inventTableModule.ModuleType = ModuleInventPurchSales::Invent;
inventTableModule.insert();

inventTableModule.initValue();
inventTableModule.ItemId = inventTable.ItemId;
inventTableModule.ModuleType = ModuleInventPurchSales::Purch;
inventTableModule.insert();

inventTableModule.initValue();
inventTableModule.ItemId = inventTable.ItemId;
inventTableModule.ModuleType = ModuleInventPurchSales::Sales;
inventTableModule.insert();

//Create inventItemLocation
InventItemLocation::createDefault(inventTable.ItemId);

// Creates a new item default order type for the product that is released.

inventItemSetupSupplyType.initValue();
inventItemSetupSupplyType.ItemId = inventTable.ItemId;
inventItemSetupSupplyType.ItemDataAreaId = inventTable.DataAreaId;
inventItemSetupSupplyType.insert();

//create relationship tables to dimension groups.

ecoResStorageDimensionGroupProduct = EcoResStorageDimensionGroupProduct::findByProduct(ecoResProduct.RecId);
ecoResTrackingDimensionGroupProduct = EcoResTrackingDimensionGroupProduct::findByProduct(ecoResProduct.RecId);

if (ecoResStorageDimensionGroupProduct.RecId)
{ // mandatory storage dimension group for the product
ecoResStorageDimensionGroupItem.ItemDataAreaId = inventTable.DataAreaId;
ecoResStorageDimensionGroupItem.ItemId = inventTable.ItemId;
ecoResStorageDimensionGroupItem.StorageDimensionGroup = ecoResStorageDimensionGroupProduct.StorageDimensionGroup;
ecoResStorageDimensionGroupItem.insert();
}

if (ecoResTrackingDimensionGroupProduct.RecId)
{ // mandatory tracking dimension group for the product
ecoResTrackingDimensionGroupItem.ItemDataAreaId = inventTable.DataAreaId;
ecoResTrackingDimensionGroupItem.ItemId = inventTable.ItemId;
ecoResTrackingDimensionGroupItem.TrackingDimensionGroup = ecoResTrackingDimensionGroupProduct.TrackingDimensionGroup;
ecoResTrackingDimensionGroupItem.insert();
}
ttsCommit;
info(strfmt(“Product successfully released to ‘RAX’ legal entity”));
}
}

In Microsoft Dynamics AX 2012 inventory dimensions have been divided into the following three categories:
Product dimensions:These correspond to the old item dimensions.
Storage dimensions:These are Site, Warehouse, Location, and Pallet.
Tracking dimensions:These are Batch number and Serial number.

Happy Dax6ng,
Sreenath

Advertisements

7 Responses to “Release products to the legal entities using X++ [Dynamics AX 2012]”

  1. Udhay Says:

    This is a great article. Thank you very much.

  2. Udhay Says:

    Actually i have released the product, but the related variants has not been released. Shall you suggest a way to release the variants also during the productmaster release?.. Thanks a lot.

    • Sreenath Reddy Says:

      Are you looking to release the variants through code or would you like to know the process in AX 2012.

      Sree

      • Udhay Says:

        Thanks much for your reply.

        yes i would like to release the variants through code. for example, i have created many variants for the product “‘2_ford'” and these variants needs to be released along with Product Release as mentioned in code below. I have tried with ecoResProductVariantReleaseManager class but couldn’t succeded.

        Any help would be great.
        Thanks.

        static void SR_ReleaseProducts(Args _args)
        {
        EcoResProduct ecoResProduct;
        EcoResProductMaster ecoResProductM;
        EcoResProductVariantReleaseManager ecoResProductVariantReleaseMgr;
        ;

        ecoResProductM.DisplayProductNumber == ‘2_ford’;
        EcoResProductReleaseManagerBase::releaseProduct(ecoResProductM.RecId,CompanyInfo::findDataArea(‘dat’).RecId);
        ecoResProductVariantReleaseMgr.release();
        }

        Thanks
        Udhay

      • Sreenath Reddy Says:

        Udhay,
        You have just created an object and trying to call the method – release.

        EcoResProductReleaseManagerBase releaseManager = EcoResProductReleaseManagerBase::createReleaseManager(ecoResProduct);

        releaseManager.release();

        please note: I didnot get chance to test this. I just verfiied code and saw this code. Test the same and let me know if it works.

        Good day!
        Sreenath

  3. Nag K Says:

    Hi Udhay,

    Below code will release varaints to legal entity.

    In my sample, i used color and size dimensions.
    If they don’t exist, below code will create those dimensions (color & size), unique variant and then releases to legal entity.

    container productDimensions;
    EcoResProductRecId distincProductVariantRecId;

    //Add Size
    productDimensions = EcoResProductVariantDimValue::getDimensionValuesContainer(”, ‘size8’, ”);
    distincProductVariantRecId = EcoResProductVariantManager::findDistinctProductVariant(ecoResProductMaster.RecId, productDimensions).RecId;
    if (!distincProductVariantRecId)
    EcoResProductMasterManager::addProductDimensionValue(
    ecoResProductMaster.RecId,
    EcoResProductDimensionAttribute::inventDimFieldId2DimensionAttributeRecId(fieldNum(InventDim, InventSizeId)),
    ‘size8’,
    ‘sizeDesc’,
    ‘sizeDesc’);

    //Add Color
    productDimensions = EcoResProductVariantDimValue::getDimensionValuesContainer(”, ”, ‘colorBLU’);
    distincProductVariantRecId = EcoResProductVariantManager::findDistinctProductVariant(ecoResProductMaster.RecId, productDimensions).RecId;
    if (!distincProductVariantRecId)
    EcoResProductMasterManager::addProductDimensionValue(
    ecoResProductMaster.RecId,
    EcoResProductDimensionAttribute::inventDimFieldId2DimensionAttributeRecId(fieldNum(InventDim, InventColorId)),
    ‘colorBLU’,
    ‘coloDesc’,
    ‘coloDesc’);

    //Add Size & Color
    productDimensions = EcoResProductVariantDimValue::getDimensionValuesContainer(”, ‘size8’, ‘colorBLU’);
    distincProductVariantRecId = EcoResProductVariantManager::findDistinctProductVariant(productMasterRecId, productDimensions).RecId;
    if (!distincProductVariantRecId)
    distincProductVariantRecId = EcoResProductVariantManager::createProductVariant(ecoResProductMaster.RecId, ”, productDimensions);

    //release variant back
    EcoResProductReleaseManagerBase::releaseProduct(distincProductVariantRecId, CompanyInfo::findDataArea(curext()).RecId);

    Nag

  4. Jagannath Tripathy Says:

    great artcile thanks a lot


Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s

%d bloggers like this: