How to get Category Hierarchy of a Product using X++
Views (7293)
Today i am going to show how we can get the Category Hierarchy of a product using X++ code.It's a handy code in various situations where we want to display the complete hierarchy of the a product.
Here is the code snippet,
ItemId itemId = "0036"; // Laptop Backpack
EcoResProductCategory EcoResProductCategory;
EcoResCategory EcoResCategory,EcoResCategoryNext;
EcoResCategoryId parentCategory;
List li = new List(Types::String);
ListEnumerator enumer;
select * from EcoResCategory
join RecId from EcoResProductCategory
where EcoResCategory.RecId == EcoResProductCategory.Category
&& EcoResProductCategory.Product == InventTable::find(itemId).Product;
parentCategory = EcoResCategory.ParentCategory;
while (parentCategory)
{
li.addStart(EcoResCategory.Name);
select * from EcoResCategory
where EcoResCategory.RecId == parentCategory
&& EcoResCategory.ParentCategory != 0; // skip the top node
parentCategory = EcoResCategory.ParentCategory;
}
enumer = li.getEnumerator();
while (enumer.moveNext())
{
info(enumer.current());
}
This is what the result looks like.
Happy DAXing :)
This was originally posted here.

Like
Report

*This post is locked for comments