Skip to main content

Notifications

Finance | Project Operations, Human Resources, ...
Answered

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

(0) ShareShare
ReportReport
Posted on by
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?
  • Martin Dráb Profile Picture
    Martin Dráb 230,962 Most Valuable Professional on at
    Find if product forms part of a child /sub child category
    Yes, it looks fine to me.
  • Verified answer
    Jason0810M Profile Picture
    Jason0810M on at
    Find if product forms part of a child /sub child category
    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.
  • Verified answer
    Martin Dráb Profile Picture
    Martin Dráb 230,962 Most Valuable Professional on at
    Find if product forms part of a child /sub child category
    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... :-(

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

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Congratulations to the January Top 10 leaders!

Check out the January community rock stars...

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,162 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 230,962 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans