Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics AX (Archived)

Create Product in Ax 2012 using X++ Code

Posted on by 286

Hi,

How to create a product and release that product based on Company using X++ or manual ax 2012 ??

thanks, advance.. :)

*This post is locked for comments

  • Suggested answer
    Santosh Yadav Profile Picture
    Santosh Yadav 420 on at
    RE: Create Product in Ax 2012 using X++ Code

    use below job, it takes data from excel and create/release product in your current LE - tweak it as needed.

    static void createAndReleaseProduct(Args _args)

    {

       EcoResProductService                    ecoResProdService;

       EcoResEcoResProduct                     ecoResProd;

       EcoResEcoResProduct_Product             product;

       EcoResEcoResProduct_Translation         translation;

       EcoResEcoResProduct_Identifier          identifier;

       EcoResEcoResProduct_ProductDimGroup     productDimGroup;

       EcoResEcoResProduct_TrackingDimGroup    trackingDimGroup;

       EcoResEcoResProduct_StorageDimGroup     storageDimGroup;

       InventModelGroupItem                    inventModelGroupItem;

       InventItemGroupItem                     inventItemGroupItem;

       InventTable                             inventTable;

       DimensionAttributeValueSetStorage       storage;

       container                               dimAttributeList;

       container                               dimValueList;

       int                                     i;

       DimensionDefault                        defaultDimension;

       SysExcelApplication                     application;

       SysExcelWorkbooks                       workbooks;

       SysExcelWorksheets                      worksheets;

       SysExcelWorksheet                       worksheet;

       SysExcelCells                           cells;

       COMVariantType                          type;

       int                                     row;

       str                                     productName;

       str                                     storageDim;

       str                                     trackingDim;

       str                                     itemModelGroup;

       str                                     itemGroupItem;

       str                                     prodDimGroup;

       Name                                    searchName;

       application = SysExcelApplication::construct();

       workbooks   = application.workbooks();

       //specify the file path that you want to read

       workbooks.open(@'C:\item.xlsx');

       worksheets  = workbooks.item(1).worksheets();

       worksheet   = workbooks.item(1).worksheets().itemFromNum(1);

       cells       = worksheet.cells();

       do

       {

           row ++;

           productName     = cells.item(row, 1).value().bStr();

           searchName      = cells.item(row, 2).value().bStr();

           storageDim      = cells.item(row, 3).value().bStr();

           trackingDim     = cells.item(row, 4).value().bStr();

           itemModelGroup  = cells.item(row, 5).value().bStr();

           itemGroupItem   = cells.item(row, 6).value().bStr();

           type            = cells.item(row+1, 1).value().variantType();

           //Initialize the service object

           ecoResProdService   = EcoResProductService::construct();

           ecoResProd          = new EcoResEcoResProduct();

           product             = new EcoResEcoResProduct_Product_Distinct();

           //Newly created and initialize prodMaster

           product.parmDisplayProductNumber(productName);

           product.parmProductType(EcoResProductType::Item);

           product.parmSearchName(searchName);

           //Create a new translation object:

           translation = product.createTranslation().addNew();

           translation.parmDescription("product");

           translation.parmLanguageId("en-us");

           translation.parmName("Product data");

           identifier = product.createIdentifier().addNew();

           identifier.parmProductNumber(productName);

           // Storage dimension

           storageDimGroup = product.createStorageDimGroup().addNew();

           storageDimGroup.parmProduct(productName);

           storageDimGroup.parmStorageDimensionGroup(storageDim);

           // tracking dimension

           trackingDimGroup = product.createTrackingDimGroup().addNew();

           trackingDimGroup.parmProduct(productName);

           trackingDimGroup.parmTrackingDimensionGroup(trackingDim);

           ecoResProd.createProduct().add(product);

           ecoResProdService.create(ecoResProd);

           // Release to current legal entity

           EcoResProductReleaseManager::releaseProductWithLegalEntityData(EcoResProduct::findByProductNumber(productName).RecId,

                                                                          CompanyInfo::findDataArea(curext()).RecId,

                                                                          productName,

                                                                          searchName);

           inventTable = InventTable::find(productName);

           inventModelGroupItem.clear();

           // insert entry to inventModelGroupItem

           inventModelGroupItem.ModelGroupId           = itemModelGroup;

           inventModelGroupItem.ItemDataAreaId         = inventTable.dataAreaId;

           inventModelGroupItem.ModelGroupDataAreaId   = inventTable.dataAreaId;

           inventModelGroupItem.ItemId                 = inventTable.ItemId;

           inventModelGroupItem.insert();

           inventItemGroupItem.clear();

           // insert entry to inventItemGroupItem

           inventItemGroupItem.ItemDataAreaId          = inventTable.dataAreaId;

           inventItemGroupItem.ItemId                  = inventTable.ItemId;

           inventItemGroupItem.ItemGroupId             = itemGroupItem;

           inventItemGroupItem.ItemGroupDataAreaId     = inventTable.dataAreaId;

           inventItemGroupItem.insert();

           info(strfmt('Product %1 imported and released to legal entity %2.', productName, CompanyInfo::findDataArea(curext()).Name));

       }

       while (type != COMVariantType::VT_EMPTY);

       {

           application.quit();

       }

    }

  • Suggested answer
    vivo88 Profile Picture
    vivo88 1,066 on at
    RE: Create Product in Ax 2012 using X++ Code

    Please refer the below link to create Products in AX 2012 using X++ code:

    pawansaxblog.blogspot.in/.../how-to-create-product-in-ax2012-using-x.html

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,235 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans