Category Hierarchy of a Product


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)

select * from EcoResCategory
where EcoResCategory.RecId ==  parentCategory
&& EcoResCategory.ParentCategory != 0;  // skip the top node

parentCategory = EcoResCategory.ParentCategory;

enumer = li.getEnumerator();
while (enumer.moveNext())


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s