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

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Suggested Answer

How to get Category Name of an ItemId of Level 3

(0) ShareShare
ReportReport
Posted on by 198

Hi there, we are developing Stock Analysis report for which there is a field Category Name which needs to populate EcoresCategory.Name value for an ItemId but the Level Should be 3. For exmaple  Take ItemId: 12345 for which the  Hierarchy Levels are  (Level1 > Level2 > Level3 > Level4>Level5).  We need to consider only Level 3 CategoryName and needs to print value accordingly for selected ItemId from InventTrans. Please suggest accordingly. 

CategoryName = EcoresCategory.Name

Level = EcoresCategory.Level  (We need to capture Level - 3)

ItemId = InventTrans.ItemId

Thanks,

Prem

I have the same question (0)
  • Suggested answer
    Sergei Minozhenko Profile Picture
    23,097 on at

    Hi premK6969,

    You can find the category for the product with EcoResProductCategory: InventTable (use ItemId to find the record) -> EcoResProductCategory.Product = InventTable.Product ->EcoResCategory.RecId = EcoResProductCategory.Category

    Then you need to check if the level is greater than 3, then find the parent category via the parent category field (EcoResCategory.RecId  = EcoResCategory.ParentCategory) until the level is not equal to 3.

    Also, you can cache the search result and store in map pairs "Item category" - "3rd level category" to speed the search process and first lookup 3rd level from the map and if it's not found in the map, search from tables and put the result to map.

  • premK6969 Profile Picture
    198 on at

    Hi Sergei, Can u please be more specific since am new to this .

  • Suggested answer
    Sergei Minozhenko Profile Picture
    23,097 on at

    Hi premK6969,

    You should get something like that in the end (without the caching part)

    InventTable inventTable = InventTable::find(inventTrans.ItemId);
    
    EcoResCategory ecoResCategory = EcoResCategory::find(EcoResProductCategory::findCategoryByProduct(inventTable.Product).Category);
    
    while (ecoResCategory.Level > 3) //Create const or parameter in report for this value
    {
        ecoResCategory = ecoResCategory.getParent();
    }
    
    info(ecoResCategory.Name); //Name of 3rd level category

  • premK6969 Profile Picture
    198 on at

    Hi Sergei,  i tried with the code you provided but cant able to see the expected result. Actually i need to place this code in a method and call it in report RDP class to get the catgegory name as per the ItemId. Please find the code attached 

              ItemId _itemid;
            _itemid = any2str(852012);
            InventTable inventTable = InventTable::find(_itemid);  // For testing i tried it with ItemId = 852012
    
            EcoResCategory ecoResCategory = EcoResCategory::find(EcoResProductCategory::findCategoryByProduct(inventTable.Product).CategoryHierarchy); // Here you mentioned Category which is throwing error so i changed to Categoryhierarchy
    
            while (any2Int(ecoResCategory) > 3) //Create const or parameter in report for this value
            {
                ecoResCategory = ecoResCategory.getParent();   // While debugging here it is throwing exception error
            }
    
            info(ecoResCategory.Name); //Name of 3rd level category

  • Suggested answer
    Sergei Minozhenko Profile Picture
    23,097 on at

    Hi premK6969

    FindCategoryByProduct already returns EcoResCategory and related line of code can be simplified

    InventTable inventTable = InventTable::find(inventTrans.ItemId);
    
    EcoResCategory ecoResCategory = EcoResProductCategory::findCategoryByProduct(inventTable.Product);
    
    while (ecoResCategory.Level > 3) //Create const or parameter in report for this value
    {
        ecoResCategory = ecoResCategory.getParent();
    }
    
    info(ecoResCategory.Name); //Name of 3rd level category

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

Season of Sharing Community Challenge Launch!

Jump in, show your community spirit, and win prizes!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the April Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Giorgio Bonacorsi Profile Picture

Giorgio Bonacorsi 676

#2
Abhilash Warrier Profile Picture

Abhilash Warrier 635 Super User 2026 Season 1

#3
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 605 Super User 2026 Season 1

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans