Tuesday, November 17, 2020

Create product master from other product details through class in ax 2012 using X++.

 

Hi guys, Today we see how to create Product master from other product details through class in ax 2012 using X++.


Run the below job.

static void productMasterCreation(Args _args)

{

    EcoResProductMaster                 ecoResProductMaster;

    InventTable                         inventTable;

    RefRecId                            _oldproductMasterRecId,productMasterRecId;

    EcoResProductDimensionGroupProduct  ecoResProductDimensionGroupProduct;

    EcoResStorageDimensionGroupItem     ecoResStorageDimensionGroupItem;

    EcoResTrackingDimensionGroupItem    ecoResTrackingDimensionGroupItem;

    EcoResProductMasterManager          productMasterManager;

    EcoResProductTranslation            ecoResProductTranslation;

    Name                                id,_name="AX";

    _oldproductMasterRecId = 22565432486;

    ecoResProductMaster = EcoResProductMaster::find(_oldproductMasterRecId);

    if (ecoResProductMaster)

    {


    inventTable = InventTable::findByProduct(ecoResProductMaster.RecId);


    ecoResProductDimensionGroupProduct = EcoResProductDimensionGroupProduct::findByProduct(ecoResProductMaster.RecId);

    ecoResStorageDimensionGroupItem  = EcoResStorageDimensionGroupItem::findByItem(inventTable.dataAreaId,inventTable.ItemId);

    ecoResTrackingDimensionGroupItem = EcoResTrackingDimensionGroupItem::findByItem(inventTable.dataAreaId,inventTable.ItemId);


    productMasterManager = EcoResProductMasterManager::construct();


    productMasterRecId = productMasterManager.createProductMaster(

                                                _name + ecoResProductMaster.DisplayProductNumber,

                                                ecoResProductMaster.SearchName,

                                                ecoResProductMaster.ProductType,

                                                ecoResProductMaster.VariantConfigurationTechnology,

                                                ecoResProductDimensionGroupProduct.ProductDimensionGroup,

                                                ecoResStorageDimensionGroupItem.StorageDimensionGroup,

                                                ecoResTrackingDimensionGroupItem.TrackingDimensionGroup);


    select firstOnly Name, Description from ecoResProductTranslation

        where ecoResProductTranslation.Product == ecoResProductMaster.RecId;


    EcoResProductTranslation::createOrUpdateTranslation(productMasterRecId, ecoResProductTranslation.Name, ecoResProductTranslation.Description);

    }

    

    info(strFmt('%1',EcoResProductMaster::find(productMasterRecId).DisplayProductNumber));

}

Keep Daxing!!

No comments:

Post a Comment