Sunday, June 14, 2015

Retail Product Hierarchy by item in AX 2012

// To Get Retail product hierarchy by Item in Job x++

static void  San_RetailItemHierarchy(Args _args)
{
    RecId                   localCatgory;
    RecId                   localHirarcghy;
    EcoResProductCategory   ecoResProdCategory;
    EcoResCategory          resCategory, loopresCategory;
    int                     i , level;
    ItemId                  _Itemid = "ItemNumber";
    Name                    Brand,Category,Grp,Division,SubGroup;
Name    BrandFN, CategoryFN,  DivisionFN,  GrpFN,  SubGroupFN;

    name cat [7];
    name catFName [7];

    ;
    for (i =1; i<= 7; i++)
    {
        cat[i] = "";
        catFname[i] = "";
    }
    ecoResProdCategory = EcoResProductCategory::findByItemIdCategoryHierarchyRole(_Itemid, EcoResCategoryNamedHierarchyRole::Retail);
    locCatgory =  ecoResProdCategory.Category;
    locHirarcghy = ecoResProdCategory.CategoryHierarchy;

    resCategory = EcoResCategory::find(locCatgory);
    level =  resCategory.Level;

    if (level > 2)
    {
    cat[level] = resCategory.Name;

    level --;

    for (i = level;  i > 2; i--)
    {
        loopCategory = resCategory.getParent();
        cat [i] = loopCategory.Name;
        catFName[i] =  EcoResCategoryTranslation::find(loopCategory.RecId, "en-us").FriendlyName;
        resCategory = loopCategory;
    }
    }
    Brand = cat[3];
    Category = cat [4];
    Division = cat [5];
    Grp = cat [6];
    SubGroup =cat  [7];

    BrandFN = catFName[3];
    CategoryFN =catFName[4];
    DivisionFN = catFName[5];
    GrpFN = catFName[6];
    SubGroupFN = catFName[7];
    info(strFmt("%1 \n Brand - %2 \n Category - %3 \n Division - %4 \n Group - %5 \n Sub group - %6",_Itemid,Brand,Category,Division,Grp,SubGroup));
 info(strFmt("%1 \n Brand - %2 \n Category - %3 \n Division - %4 \n Group - %5 \n Sub group - %6",_Itemid,BrandFN ,CategoryFN ,DivisionFN ,GrpFN ,SubGroupFN ));
 
}

No comments:

Post a Comment

Convert Call stack to readable format in D365FO X++

//Input --container _xppCallStack = xSession::xppCallStack();  Public static str POL_formatXppCallStack(container _xppCallStack, int _skipFr...