How to get info from all parent groups? (multi-layered)

  • Productgroup 1
    • Productgroup 1.1
    • Productgroup 1.2
    • Productgroup 1.3
      • Productgroup 1.3.1
      • Productgroup 1.3.2
      • Productgroup 1.3.3
        • Productgroup 1.3.3.1
    • Productgroup 1.4

Each layer of the Productgroups has QuestionConnections.
A Questionconnection is a connection between a Productgroup and a Question…
Questionconnections are stored per layer 1, 2, 3 and 4.

Question: With which expression can I get the list of all parent Questionconnections from a certain Productgroup?

So Product X has Productgroup 1.3.3.1. How to get all Questionconnections from this group + all parent groups?
(Ideally independend of the layer, but otherwise context can always be the 4th layer)

I think this sould work. The context of the expression is the questionconnection record of productgroup 1.3.3.1.

{
 questionconnections,
 this,
 boolean:or([
  productgroup.equals(parent),
  int:exists({
   questionconnections,
   1,
   boolean:or([
    parent.parent.parent_group.equals(this.productgroup),
    parent.parent.parent_group.parent_group.equals(this.productgroup),
    parent.parent.parent_group.parent_group.parent_group.equals(this.productgroup)
   ])
  })
 ])
}

I havent tested this. Should test performance with all those OR statements :slight_smile:

Hi Yori,
Check M3844 Novulo Afdelingen.
Here, I implemented full logic to support this. It’s a method that can easily be implemented in Productgroepen as well. I’d say you can do this in 2-4 hours by just having the two screens next to each other.

Redmer’s solution is limited in levels and won’t perform in big implementations

2 Likes

Hi Yori, in your scenario (i.e. the product is linked to the lowest level product group) the fx root version @ systemversions in component 4207 could also be an inspiration for your question. This function is recursive but because it’s cached it will work.

Hey Yori,
yesterday I came across component M5935 which also has an interesting recursive function in it to retrieve the warehouse of a stock location category which can be nested indefinably as well.
It might inspire you for your solution. The key is to have some sort of stop condition I guess (e.g: the parent_group is not set)

If you are not limited to an expression, you might want to build a process that adds all QuestionConnections of a group to a list and restarts over with the parent group as long as the parent is set.
Something like this: