Thursday, July 16, 2020

How to Release products in ax 2012 using X++

Hi guys, today we going to do how to  release products in ax 2012 using X++.






    InventTable                 inventTable;
    InventTableModule           inventTableModule;
    NumberSequenceTable         numberSequenceTable;
    InventItemSetupSupplyType   inventItemSetupSupplyType;
    InventModelGroupItem        inventModelGroupItem;
    InventItemGroupItem         inventItemGroupItem;
    ItemId itemId;

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

    select firstOnly ecoResProduct where EcoResProduct.DisplayProductNumber == DaxProductDetails.ProductNumber; //DaxProductDetails is my own table

        ttsBegin;
        inventTable = null;
        inventTableModule = null;
        inventItemSetupSupplyType = null;
        ecoResStorageDimensionGroupProduct = null;
        ecoResTrackingDimensionGroupProduct = null;
        ecoResStorageDimensionGroupItem = null;
        ecoResTrackingDimensionGroupItem = null;


        //Storage dimension group
        ecoResStorageDimensionGroupProduct.clear();
        ecoResStorageDimensionGroupProduct.initValue();
        ecoResStorageDimensionGroupProduct.Product               = ecoResProduct.RecId;
        ecoResStorageDimensionGroupProduct.StorageDimensionGroup = EcoResStorageDimensionGroup::findByDimensionGroupName("SiteWH").RecId;
        if (ecoResStorageDimensionGroupProduct.validateWrite())
        {
            ecoResStorageDimensionGroupProduct.insert();
        }

        //Tracking dimension group
        ecoResTrackingDimensionGroupProduct.clear();
        ecoResTrackingDimensionGroupProduct.initValue();
        ecoResTrackingDimensionGroupProduct.Product                = ecoResProduct.RecId;
        ecoResTrackingDimensionGroupProduct.TrackingDimensionGroup = EcoResTrackingDimensionGroup::findByDimensionGroupName("Serial").RecId;
        if (ecoResTrackingDimensionGroupProduct.validateWrite())
        {
            ecoResTrackingDimensionGroupProduct.insert();
        }

        itemId = ecoResProduct.productNumber();

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

        // Create invent Table Modules

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

        //Inventory model group
        inventModelGroupItem.clear();
        inventModelGroupItem.initValue();
        inventModelGroupItem.ItemDataAreaId = inventTable.dataAreaId;
        inventModelGroupItem.ItemId         = inventTable.ItemId;
        inventModelGroupItem.ModelGroupId   = "FIFO";
        inventModelGroupItem.ModelGroupDataAreaId = curext();
        inventModelGroupItem.insert();

        //Item group
        inventItemGroupItem.clear();
        inventItemGroupItem.initValue();
        inventItemGroupItem.ItemDataAreaId = inventTable.dataAreaId;
        inventItemGroupItem.ItemId         = inventTable.ItemId;
        inventItemGroupItem.ItemGroupId    = "Sevices";
        inventItemGroupItem.ItemGroupDataAreaId = curext();
        inventItemGroupItem.insert();

        //Create invent Item Location
        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();
        }



        info("Product successfully released");

Keep Daxing !!

No comments:

Post a Comment