Hi guys, Today we see how to create product master dimensions and variants in ax 2012 using X++.
Run the below job.
static void createDimesionsAndVariants(Args _args)
{
EcoResProductMaster ecoResProductMaster;
EcoResConfiguration ecoResConfiguration;
EcoResProductMasterConfiguration productMasterConfiguration;
EcoResDistinctProductVariant ecoResDistinctProductVariant;
InventDim inventDim;
RefRecId _productMasterRecId;
container con,dimensionValues;
int i=1;
con = ['1001','1002','1003'];
_productMasterRecId = 52565460661;
ecoResProductMaster = EcoResProductMaster::find(_productMasterRecId);
if (ecoResProductMaster)
{
for (i=1 ; i<=conLen(con) ; i++)
{
ecoResConfiguration = EcoResConfiguration::findByName(conPeek(con, i));
if (!ecoResConfiguration)
{
ecoResConfiguration.clear();
ecoResConfiguration.initValue();
ecoResConfiguration.Name = conPeek(con,i);
ecoResConfiguration.insert();
}
select firstOnly RecId from inventDim
where inventDim.configId == ecoResConfiguration.Name;
if (!inventDim.RecId)
{
inventDim.clear();
inventDim.ConfigId = ecoResConfiguration.Name;
inventDim = InventDim::create(inventDim);
}
productMasterConfiguration = EcoResProductMasterConfiguration::find(ecoResProductMaster.RecId,ecoResConfiguration.RecId);
if (!productMasterConfiguration)
{
productMasterConfiguration.clear();
productMasterConfiguration.initValue();
productMasterConfiguration.ConfigProductMaster = ecoResProductMaster.RecId;
productMasterConfiguration.Configuration = ecoResConfiguration.RecId;
productMasterConfiguration.ConfigProductDimensionAttribute = EcoResProductDimensionAttribute::inventDimFieldId2DimensionAttributeRecId(fieldNum(InventDim, ConfigId));
productMasterConfiguration.insert();
}
dimensionValues = EcoResProductVariantDimValue::getDimensionValuesContainer(ecoResConfiguration.Name);
ecoResDistinctProductVariant = EcoResProductVariantManager::findDistinctProductVariant(ecoResProductMaster.RecId,dimensionValues);
if (!ecoResDistinctProductVariant)
{
EcoResProductVariantManager::createProductVariant(ecoResProductMaster.RecId,
EcoResProduct::find(ecoResProductMaster.RecId).SearchName + ecoResConfiguration.Name,
dimensionValues);
}
}
}
}
Keep Daxing!!
No comments:
Post a Comment