Creating Product Master with configuration and it’s variant, then releasing it – Bojensen Blogs
Bojensen Blogs

Creating Product Master with configuration and it’s variant, then releasing it

Here is an example I found on GitHub on how to create a new Product Master with variants and then release it in AX2012.

static void CreateProduct(Args _args) { EcoResProductMasterManager manager = EcoResProductMasterManager::construct(); recId productMasterRecId; EcoResDistinctProductVariant productVariant; EcoResProductVariantCreationMgr productVariantCreationMgr = new EcoResProductVariantCreationMgr(); container productVariantContainer; EcoResProductVariantDimValue productVariantDimValue; EcoResTmpProductVariantSuggestion productVariantSuggestion; EcoResProductDimGroupSetup productDimGroupSetup = EcoResProductDimGroupSetup::construct(); EcoResProductMasterConfiguration productMasterConfiguration; EcoResConfiguration productConfiguration; EcoResProductReleaseSessionManager releaseSessionManager = EcoResProductReleaseSessionManager::newReleaseSession(); try { ttsBegin; //Creates product master productMasterRecId = manager.createProductMaster("Product Name", "Product Search Name", EcoResProductType::Item, EcoResVariantConfigurationTechnologyType::PredefinedVariants, 5637144576, //EcoResProductDimensionGroup::findByDimensionGroupName("CONFIG").RecId, //Product Group 5637144576, //EcoResStorageDimensionGroup::findByDimensionGroupName("STODIM01").RecId, //Product Tracking Dimension 5637144826); //EcoResTrackingDimensionGroup::findByDimensionGroupName("TRKDIM02").RecId); //Product Tracking Dimension //Creates product master translations EcoResProductTranslation::createOrUpdateTranslation(productMasterRecId, "Product Name", "Product Name Desc", "en-us"); productMasterConfiguration.ConfigProductMaster = productMasterRecId; productMasterConfiguration.Configuration = 5637144593; //productConfiguration = EcoResConfiguration::findByName("STD"); productmasterconfiguration.Description = "Product Standard configuration"; productMasterConfiguration.AdditionalDescription = "Product Additional Description"; productMasterConfiguration.ConfigProductDimensionAttribute = EcoResProductDimensionAttribute::inventDimFieldId2DimensionAttributeRecId(fieldNum(InventDim, ConfigId)); productMasterConfiguration.insert(); productVariantContainer = EcoResProductVariantDimValue::getDimensionValuesContainer("STD"); //precreated configuration dimension EcoResProductVariantManager::createProductVariant(productMasterRecId, "Variant A", productVariantContainer); releaseSessionManager.addProductMasterWithVariants(productMasterRecId); releaseSessionManager.addLegalEntityForAllProducts(xDataArea::find(curext()).RecId); releaseSessionManager.execute(); ttsCommit; } catch { ttsAbort; } }

 

Creating Product Master with configuration and it’s variant, then releasing it

Comments are closed.