How to release products to all companies.

Hi,

As you know with Dynamics AX 2012, you have to create a product first and then release to the product to companies. You can release which company do you want. In my company there is a request to release product all companies automaticly. I have some research and found good post and methods about it. I wrote a class named SECReleaseProductForAllCompanies and make it MenuItemButton as you can see below.

Let see methods of class now.

Class decleration;

// FD Relaese products for all companies
class SECReleaseProductForAllCompanies
{
    EcoResProductDisplayProductNumber   productNumber;
    EcoResProduct                       ecoResProduct;
}

Main method; Gets all the selected records and calls run.

public static void main(Args args)
{
    SECReleaseProductForAllCompanies    releaseProductForAllCompanies;
    ecoResProduct                       EcoResProduct;
    FormDataSource                      fdsEcoResProduct;
    ;

    fdsEcoResProduct = args.record().dataSource();
    for (EcoResProduct = fdsEcoResProduct.getFirst(true) ? fdsEcoResProduct.getFirst(true) :
            fdsEcoResProduct.cursor();   EcoResProduct; EcoResProduct = fdsEcoResProduct.getnext())
    {
        releaseProductForAllCompanies = new SECReleaseProductForAllCompanies();
        releaseProductForAllCompanies.parmProductNumber(ecoResProduct.DisplayProductNumber);
        releaseProductForAllCompanies.run();

        info(strfmt("%1  %2 product successfully released to all companies. ",
                    EcoResProduct.productNumber() , EcoResProduct.productName() ));
    }
}

Parm method;

public EcoResProductDisplayProductNumber parmProductNumber(
            EcoResProductDisplayProductNumber _productNumber = productNumber)
{
    productNumber = _productNumber;

    return productNumber;
}

Run method;

private void run()
{
    ;
    this.releaseProduct();
}

Release method; You can use EcoResProductReleaseManagerBase::releaseProduct() static method instead of this.

private void releaseProduct()
{
    InventTable                 inventTable;
    InventTableModule           inventTableModule;
    NumberSequenceTable         numberSequenceTable;
    ItemId                      itemId;
    InventItemSetupSupplyType   inventItemSetupSupplyType;
    CompanyInfo                 companyInfo;

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

    select firstOnly ecoResProduct
        where EcoResProduct.DisplayProductNumber == productNumber;

    while select companyInfo
        where companyInfo.DataArea != "DAT"
    {
        changecompany (companyInfo.DataArea)
        {
            ttsBegin;
            inventTable = null;
            inventTableModule = null;
            inventItemSetupSupplyType = null;
            ecoResStorageDimensionGroupProduct = null;
            ecoResTrackingDimensionGroupProduct = null;
            ecoResStorageDimensionGroupItem = null;
            ecoResTrackingDimensionGroupItem = null;

            numberSequenceTable = InventParameters::numRefItemId().numberSequenceTable();

            if (!numberSequenceTable.RecId || numberSequenceTable.Manual)
            {
                itemId = ecoResProduct.productNumber();
            }
            else
            {
                itemId = NumberSeq::newGetNumFromId(numberSequenceTable.RecId).num();
            }

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

            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();

            InventItemLocation::createDefault(inventTable.ItemId);

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

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

            if (ecoResStorageDimensionGroupProduct.RecId)
            {
                ecoResStorageDimensionGroupItem.ItemDataAreaId = inventTable.DataAreaId;
                ecoResStorageDimensionGroupItem.ItemId = inventTable.ItemId;
                ecoResStorageDimensionGroupItem.StorageDimensionGroup = ecoResStorageDimensionGroupProduct.StorageDimensionGroup;
                ecoResStorageDimensionGroupItem.insert();
            }

            if (ecoResTrackingDimensionGroupProduct.RecId)
            {
                ecoResTrackingDimensionGroupItem.ItemDataAreaId = inventTable.DataAreaId;
                ecoResTrackingDimensionGroupItem.ItemId = inventTable.ItemId;
                ecoResTrackingDimensionGroupItem.TrackingDimensionGroup = ecoResTrackingDimensionGroupProduct.TrackingDimensionGroup;
                ecoResTrackingDimensionGroupItem.insert();
            }

            ttsCommit;

        }
    }
}


You can download class from here.

Thanks Sreenath Reddy G. for methods.

Until next time.

 
Comment are closed.