Thursday, July 23, 2020

How to create Product Master and Release in Ax 2012 using X++

Hi guys, today we see how to create Product master and Release in ax 2012 using X++.
 Just write below code in job and test it.
 Do the changes to your reqirment.


static void productMasterCreationAndRelease(Args _args) { EcoResProductMaster ecoResProductMaster; EcoResProductIdentifier ecoResProductIdentifier; EcoResProductTranslation ecoResProductTranslation; EcoResProductDimensionGroupProduct ecoResProductDimensionGroupProduct; InventTable inventTable; InventModelGroupItem inventModelGroupItem; InventItemGroupItem inventItemGroupItem; InventTableModule inventTableModule; InventItemSetupSupplyType inventItemSetupSupplyType; EcoResStorageDimensionGroupItem ecoResStorageDimensionGroupItem; EcoResTrackingDimensionGroupItem ecoResTrackingDimensionGroupItem; EcoResStorageDimensionGroupProduct ecoResStorageDimensionGroupProduct; EcoResTrackingDimensionGroupProduct ecoResTrackingDimensionGroupProduct; EcoResProductMasterModelingPolicy ecoResProductMasterModelingPolicy; EcoResConfiguration ecoResConfiguration; EcoResProductMasterConfiguration ecoResProductMasterConfiguration; EcoResSize ecoResSize; EcoResProductMasterSize ecoResProductMasterSize; EcoResColor ecoResColor; EcoResProductMasterColor ecoResProductMasterColor; InventDim inventDim; ItemId itemId="kalyan91113"; ItemName itemName="kalyan91113"; // Product master Creation; //ProductMaster ecoResProductMaster.clear(); ecoResProductMaster.initValue(); ecoResProductMaster.ProductType = EcoResProductType::Item; ecoResProductMaster.DisplayProductNumber = itemId;//ProductNumber.valueStr(); ecoResProductMaster.SearchName =itemName;// SearchName.valueStr(); ecoResProductMaster.VariantConfigurationTechnology = EcoResVariantConfigurationTechnologyType::PredefinedVariants; if(ecoResProductMaster.validateWrite()) { ecoResProductMaster.insert(); } //Product Identifer ecoResProductIdentifier.clear(); ecoResProductIdentifier.initValue(); ecoResProductIdentifier.ProductNumber = itemId;//ProductNumber.valueStr(); ecoResProductIdentifier.Product = ecoResProductMaster.RecId; ecoResProductIdentifier.insert(); //Product dimension group ecoResProductDimensionGroupProduct.clear(); ecoResProductDimensionGroupProduct.initValue(); ecoResProductDimensionGroupProduct.initFromProduct(ecoResProductMaster); ecoResProductDimensionGroupProduct.ProductDimensionGroup = EcoResProductDimensionGroup::findByDimensionGroupName('SizeColCon').RecId; if(ecoResProductDimensionGroupProduct.validateWrite()) { ecoResProductDimensionGroupProduct.insert(); } //Storage dimension group ecoResStorageDimensionGroupProduct.clear(); ecoResStorageDimensionGroupProduct.initValue(); ecoResStorageDimensionGroupProduct.Product = ecoResProductMaster.RecId; ecoResStorageDimensionGroupProduct.StorageDimensionGroup = EcoResStorageDimensionGroup::findByDimensionGroupName("Site").RecId; if (ecoResStorageDimensionGroupProduct.validateWrite()) { ecoResStorageDimensionGroupProduct.insert(); } //Tracking dimension group ecoResTrackingDimensionGroupProduct.clear(); ecoResTrackingDimensionGroupProduct.initValue(); ecoResTrackingDimensionGroupProduct.Product = ecoResProductMaster.RecId; ecoResTrackingDimensionGroupProduct.TrackingDimensionGroup = EcoResTrackingDimensionGroup::findByDimensionGroupName("Serial").RecId; if (ecoResTrackingDimensionGroupProduct.validateWrite()) { ecoResTrackingDimensionGroupProduct.insert(); } //Product modeling policy ecoResProductMasterModelingPolicy.clear(); ecoResProductMasterModelingPolicy.initValue(); ecoResProductMasterModelingPolicy.ProductMaster = ecoResProductMaster.RecId; if (ecoResProductMasterModelingPolicy.validateWrite()) { ecoResProductMasterModelingPolicy.insert(); } EcoResProductTranslation::createOrUpdateTranslation(ecoResProductMaster.RecId, itemId, itemName); //Configuration ecoResConfiguration = EcoResConfiguration::findByName("Pen"); if (!ecoResConfiguration) { ecoResConfiguration.clear(); ecoResConfiguration.initValue(); ecoResConfiguration.Name = "Pen "; ecoResConfiguration.insert(); } //Size ecoResSize = EcoResSize::findByName("1"); if(!ecoResSize) { ecoResSize.clear(); ecoResSize.initValue(); ecoResSize.Name = "1 "; ecoResSize.insert(); } //color ecoResColor = EcoResColor::findByName("Blue"); if(!ecoResColor) { ecoResColor.clear(); ecoResColor.initValue(); ecoResColor.Name = "Blue"; ecoResColor.insert(); } //InventDimId Creating inventDim.clear(); inventDim.ConfigId = "Pen"; inventDim.InventSizeId = "1"; //size inventDim.InventColorId = "Blue"; // name inventDim = InventDim::findOrCreate(inventDim); //Configuration assigned to product master ecoResProductMasterConfiguration.clear(); ecoResProductMasterConfiguration.initValue(); ecoResProductMasterConfiguration.Configuration = ecoResConfiguration.RecId; ecoResProductMasterConfiguration.ConfigProductDimensionAttribute = EcoResProductDimensionAttribute::inventDimFieldId2DimensionAttributeRecId(fieldNum(InventDim, ConfigId)); ecoResProductMasterConfiguration.ConfigProductMaster = ecoResProductMaster.RecId; ecoResProductMasterConfiguration.insert(); //Size assigned to product master ecoResProductMasterSize.clear(); ecoResProductMasterSize.initValue(); ecoResProductMasterSize.Size = ecoResSize.RecId; ecoResProductMasterSize.SizeProductDimensionAttribute = EcoResProductDimensionAttribute::inventDimFieldId2DimensionAttributeRecId(fieldNum(InventDim, InventSizeId)); ecoResProductMasterSize.SizeProductMaster = ecoResProductMaster.RecId; //color assigned to product master ecoResProductMasterColor.clear(); ecoResProductMasterColor.initValue(); ecoResProductMasterColor.Color = ecoResColor.RecId; ecoResProductMasterColor.ColorProductDimensionAttribute = EcoResProductDimensionAttribute::inventDimFieldId2DimensionAttributeRecId(fieldNum(InventDim, InventColorId)); ecoResProductMasterColor.ColorProductMaster = ecoResProductMaster.RecId; info('product master created'); //Release product master inventTable.clear(); inventTable.initValue(); inventTable.initFromEcoResProduct(ecoResProductMaster); inventTable.ItemId = itemId;//itemIdProductNumber.valueStr(); inventTable.NameAlias =itemName;// Name.valueStr(); if (inventTable.validateWrite()) { inventTable.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 = "Parts"; inventItemGroupItem.ItemGroupDataAreaId = curext(); inventItemGroupItem.insert(); //Extended product details – Inventory inventTableModule.clear(); inventTableModule.initValue(); inventTableModule.ItemId = inventTable.ItemId; inventTableModule.ModuleType = ModuleInventPurchSales::Invent; inventTableModule.insert(); //Extended product details – Purchase inventTableModule.clear(); inventTableModule.initValue(); inventTableModule.ItemId = inventTable.ItemId; inventTableModule.ModuleType = ModuleInventPurchSales::Purch; inventTableModule.insert(); //Extended product details – Sales inventTableModule.clear(); inventTableModule.initValue(); inventTableModule.ItemId = inventTable.ItemId; inventTableModule.ModuleType = ModuleInventPurchSales::Sales; inventTableModule.insert(); //Warehouse items InventItemLocation::createDefault(inventTable.ItemId); //Supply type setup inventItemSetupSupplyType.clear(); inventItemSetupSupplyType.initValue(); inventItemSetupSupplyType.ItemId = inventTable.ItemId; inventItemSetupSupplyType.ItemDataAreaId = inventTable.DataAreaId; inventItemSetupSupplyType.insert(); //Product storage dimension group ecoResStorageDimensionGroupProduct = EcoResStorageDimensionGroupProduct::findByProduct(ecoResProductMaster.RecId); if (ecoResStorageDimensionGroupProduct.RecId) { ecoResStorageDimensionGroupItem.clear(); ecoResStorageDimensionGroupItem.initValue(); ecoResStorageDimensionGroupItem.ItemDataAreaId = inventTable.DataAreaId; ecoResStorageDimensionGroupItem.ItemId = inventTable.ItemId; ecoResStorageDimensionGroupItem.StorageDimensionGroup = ecoResStorageDimensionGroupProduct.StorageDimensionGroup; ecoResStorageDimensionGroupItem.insert(); } //Product tracking dimension group ecoResTrackingDimensionGroupProduct = EcoResTrackingDimensionGroupProduct::findByProduct(ecoResProductMaster.RecId); if (ecoResTrackingDimensionGroupProduct.RecId) { ecoResTrackingDimensionGroupItem.clear(); ecoResTrackingDimensionGroupItem.initValue(); ecoResTrackingDimensionGroupItem.ItemDataAreaId = inventTable.DataAreaId; ecoResTrackingDimensionGroupItem.ItemId = inventTable.ItemId; ecoResTrackingDimensionGroupItem.TrackingDimensionGroup = ecoResTrackingDimensionGroupProduct.TrackingDimensionGroup; ecoResTrackingDimensionGroupItem.insert(); } info('product Realeased'); } }



Keep Daxing !!

No comments:

Post a Comment