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

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Answered

Find if product forms part of a child /sub child category

(0) ShareShare
ReportReport
Posted on by 8
Hello,
 
I have a scenario where assuming we have EcoResCategory categories A which contains a child category B and B contains C as follows in terms of hierarchy:
//////
I have an item 100000 which is found in the category C. I have a validation check to do as follows:
If ever some one selects category A and product 100000 on a new custom form, it should return true as technically the product 100000 is found in its sub child C. Same applies for B.
I am having trouble to do this. I tried using the methods getDescendants and getChildren. However, it is not performance friendly and it is not working properly.
Is it possible to do this in a single select statement?
  • Verified answer
    Martin Dráb Profile Picture
    240,744 Most Valuable Professional on at
    Pay attention to fields called NestedSetLeft and NestedSetRight. If you want to know whether C is contained in A, check if the range of the nested set is contained.
     
    For example, let's say that the range of A is <1, 100>, B has <30, 60> and C <40, 50>, while a node D not belonging under A has <120, 130>. You can easily say that <40, 50> is in <1, 100>, therefore C is a subcategory of A.
     
    Does it makes sense?
     
    I planned to write a blog post about it, but I keep postponing it... :-(
  • Verified answer
    Jason0810M Profile Picture
    8 on at
    Hello Martin,
    I have followed your advice and implemented a method in EcoResProductCategory extensionn using the hierarchy structure.
    It looks to be working. I am passing the item's productRecId and the category's ecoResCategory to be checked.
    Let me know if it is okay. Thanks.
  • Martin Dráb Profile Picture
    240,744 Most Valuable Professional on at
    Yes, it looks fine to me.

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 Winners!

Congratulations to our community stars!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the July Top 10 Community Leaders

These are the community rock stars!

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

#1
Martin Dráb Profile Picture

Martin Dráb 426 Most Valuable Professional

#2
CU10121822-0 Profile Picture

CU10121822-0 358

#3
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 353 Super User 2026 Season 2

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans