web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

X++ How to get Product Category Hierarchy

(0) ShareShare
ReportReport
Posted on by

I have below Product Category Hierarchy setup and products is assigned to the lowest category e.g MT0001 to 6ft Rectangle. In x++ how can I retrieve all the related category hierachy in sequence for the particular product?
Any suggestion and advice will be highly appreciated.

e.g for MT0001 will return [Furniture,Office,Table, Manager, 6ft Rectangle]

Furniture
      -> Office
          -> Table
              -> Manager
                  -> 6ft Rectangle
                  -> 5ft L-Shape 

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Muhammad Yasir Profile Picture
    1,023 on at

    You can get the product category hierarchy for the product "MT0001" by using the below code.

    ItemId itemId = "MT0001";
    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;
    li.addStart(EcoResCategory.Name);

    while (parentCategory)
    {
    select * from EcoResCategory
    where EcoResCategory.RecId == parentCategory;
    //&& EcoResCategory.ParentCategory != 0;

    parentCategory = EcoResCategory.ParentCategory;
    li.addStart(EcoResCategory.Name);
    }

    enumer = li.getEnumerator();
    while (enumer.moveNext())
    {
    info(enumer.current());
    }

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#1
Priya_K Profile Picture

Priya_K 4

#3
MyDynamicsNAV Profile Picture

MyDynamicsNAV 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans