Insight into AX 2012 Product Dimensions

Situation:  Configurable product masters (Constraint-based configuration) exist without the required standard configuration

Probable cause: Setup was missing during import of product master.

Solution: Requires a script as the default configuration should have been created automatically and the form required to add configurations manually is write protected for constraint-based configurations. The creation of product variants and activation as standard configuration would be possible manually, but is covered by the script as well.

Script Overiew

  • Create product specific configuration  (Main tables involved: EcoResProductDimensionGroupProduct)
  • Create product variant (Main tables involved: EcoResDistinctProductVariant, EcoResProductVariantConfiguration; Helper Class: EcoResProductVariantManager)
  • Release product variant to company (Main tables involved: InventDimCombination, InventDim; Helper Class: EcoResProductVariantReleaseManager)
  • Set variant as default on item (Main tables involved: InventTable)
static void ecoResProductMasterConfiguration_fix(Args _args)
{
    EcoResConfiguration                 c = EcoResConfiguration::findByName(EcoResProductParameters::getConfigurationName());
    EcoResProduct                       p;
    EcoResProductMasterConfiguration    productMasterConfiguration, productMasterConfiguration_notExists;
    EcoResProductDimensionGroupProduct  productDimensionGroupProduct;
    EcoResProductDimensionGroup         productDimensionGroup = EcoResProductDimensionGroup::findByDimensionGroupName("CONFIG_GRP");
    EcoResDistinctProductVariant        distinctProductVariant, distinctProductVariant_notExists;
    RefRecId                            productVariant;
    RefRecId                            attribute = EcoResProductDimensionAttribute::inventDimFieldId2DimensionAttributeRecId(fieldNum(InventDim,configId));
    EcoResProductVariantReleaseManager  ecoResProductVariantReleaseManager;
    InventTable                         inventTable;
    InventDimCombination                inventDimCombination_notExists;
    int                                 i,u;
    ;
    //Add config to product master (this cannot be done manually - error during import)
    While select p join productDimensionGroupProduct where productDimensionGroupProduct.Product == p.RecId && productDimensionGroupProduct.ProductDimensionGroup == productDimensionGroup.RecId
        notExists join productMasterConfiguration_notExists where productMasterConfiguration_notExists.ConfigProductMaster == p.RecId && productMasterConfiguration_notExists.Configuration == c.RecId
    {
        info(p.productNumber());
        ttsBegin;
        productMasterConfiguration.initValue();
        productMasterConfiguration.ConfigProductMaster = p.RecId;
        productMasterConfiguration.Configuration = c.RecId;
        productMasterConfiguration.ConfigProductDimensionAttribute = EcoResProductDimensionAttribute::inventDimFieldId2DimensionAttributeRecId(fieldNum(InventDim,ConfigId));
        productMasterConfiguration.insert();
        ttsCommit;
        i++;
    }
    //create product variant
    While select p //debug: where p.RecId == EcoResProduct::findByProductNumber("0052999").RecId
        join productDimensionGroupProduct where productDimensionGroupProduct.Product == p.RecId && productDimensionGroupProduct.ProductDimensionGroup == productDimensionGroup.RecId
        notExists join distinctProductVariant_notExists where distinctProductVariant_notExists.ProductMaster == p.RecId //not precise, but sufficient to identify missing standard variant
    {
        info(p.productNumber());
        ttsBegin;
        productVariant = EcoResProductVariantManager::createProductVariant(p.RecId,p.SearchName,[[attribute,c.RecId]]);
        EcoResProductTranslation::createOrUpdateTranslation(productVariant, p.productName(), '');
        ttsCommit;
        i++;
    }
    //release product variant to current company
    While select forupdate inventTable
        join p where inventTable.Product == p.RecId //debug: && p.RecId == EcoResProduct::findByProductNumber("0052999").RecId
        join distinctProductVariant where distinctProductVariant.ProductMaster == p.RecId
        exists join productDimensionGroupProduct where productDimensionGroupProduct.Product == p.RecId && productDimensionGroupProduct.ProductDimensionGroup == productDimensionGroup.RecId
        notExists join inventDimCombination_notExists where inventDimCombination_notExists.ItemId == inventTable.itemId //not precise, but sufficient to identify not released standard variant
    {
        info(p.productNumber());
        ecoResProductVariantReleaseManager = EcoResProductVariantReleaseManager::construct();
        ecoResProductVariantReleaseManager.parmEcoResProduct(distinctProductVariant);
        ecoResProductVariantReleaseManager.parmLegalEntity(CompanyInfo::current());
        ecoResProductVariantReleaseManager.release();
        i++;
    }
    //set default configuration
    ttsBegin;
    While select forupdate inventTable where !inventTable.StandardConfigId
        join p where inventTable.Product == p.RecId
        exists join productDimensionGroupProduct where productDimensionGroupProduct.Product == p.RecId && productDimensionGroupProduct.ProductDimensionGroup == productDimensionGroup.RecId
    {
        info(p.productNumber());
        inventTable.StandardConfigId = c.Name;
        inventTable.update();
        u++;
    }
    ttsCommit;
    info(strFmt("%1 records inserted, %2 updated",i,u));
}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s