Iterating over a multi-level Bill of Material

Hello

I’m still fairly new to KNIME and I’m a bit stuck building a loop to generate a multi-level Bill of Material from our E1 database.

I’ve got a simple recursive loop that works fairly well but it produces a flat unordered BOM table:

Here’s what I would like to get:

The first input into my “BOM reader” is 400350012 which returns the following table:

Another issue is that I don’t know beforehand how deep the BOM is, we have some that are 10 levels deep.

The idea is also that I can input an arbitrary amount of parent items (works by wrapping a Group Loop around the whole recursive loop).

Thanks