Monday, December 9, 2013

How to create Product in Ax2012 using x++ code.

In one of my implementation I had requirement in this I had to create product in Ax using x++ code. Below code explains how we can create product in Ax2012  in a specific company.


private void createProduct(itemId                        _itemId,
                          DataAreaId                    _dataAreaId = curext()
                          )

{
    EcoResProductService                    ecoResProdService;
    EcoResEcoResProduct                     ecoResProduct;
    EcoResEcoResProduct_Product_Distinct    product;
    EcoResEcoResProduct_Translation         translation;
    EcoResEcoResProduct_Identifier          identifier;
    EcoResEcoResProduct_StorageDimGroup     storageDimGroup;
    EcoResEcoResProduct_TrackingDimGroup    trackingDimensionGroup;
    InventTable                             localInventTable;
    ;

    if (!this.isProductAlreadyExists() && this.getItemId())
    {
        localInventTable = InventTable::find(_itemId);
        //Initialize the service object
        changeCompany(_dataAreaId)
        {
            ecoResProdService = EcoResProductService::construct();
            ecoResProduct     = new EcoResEcoResProduct();
            product           = new EcoResEcoResProduct_Product_Distinct();

            //Newly created and initialize product

            product.parmDisplayProductNumber(this.getItemId());
            product.parmProductType(EcoResProductType::Item);
            product.parmSearchName(this.getItemId());

            //Create a new translation object:
            Translation = product.createTranslation().addNew();

            Translation.parmDescription(this.getItemLongDescription());
            Translation.parmLanguageId(CompanyInfo::languageId());
            Translation.parmName(this.getItemShortDescription());
            Identifier = product.createIdentifier().addNew();

            Identifier.parmProductNumber(this.getItemId());

            if (localInventTable.storageDimensionGroup())
            {
                if (EcoResStorageDimensionGroup::find(localInventTable.storageDimensionGroup()).Name)
                {
                    storageDimGroup = product.createStorageDimGroup().addNew();
                    storageDimGroup.parmProduct(this.getItemId());
                    storageDimGroup.parmStorageDimensionGroup(EcoResStorageDimensionGroup::find(localInventTable.storageDimensionGroup()).Name);
                }
            }

            if (localInventTable.trackingDimensionGroup())
            {
                if (EcoResTrackingDimensionGroup::find(localInventTable.trackingDimensionGroup()).Name)
                {
                    trackingDimensionGroup = product.createTrackingDimGroup().addNew();
                    trackingDimensionGroup.parmProduct(this.getItemId());
                    trackingDimensionGroup.parmTrackingDimensionGroup(EcoResTrackingDimensionGroup::find(localInventTable.trackingDimensionGroup()).Name);
                }
            }

            ecoResProduct.createProduct().add(product);
            ecoResProdService.create(ecoResProduct);
            }
        }
}

2 comments:

  1. Casinos Near Harrah's Philadelphia - Mapyro
    Find 광양 출장샵 Casinos 충주 출장마사지 Near 상주 출장마사지 Harrah's Philadelphia, PA near 충주 출장안마 Chester, United States and other United States. 2,500 casino slot machines, 양주 출장샵 16 tables poker tables and 2,500 slot

    ReplyDelete