BPM collect manufactured sub parts from bom

Hi,

Maybe be someone ever created something like that using BPM and C#. Lets say situation like this:
I have main manufactured part bom which contains another manufactured bom under materials, this second level bom also contains manufactured sub bom under materials. the task is after specific action to collect all these header part numbers of first second and in some cases third level part numbers and to store these part numbers for further loop to make changes in their datasets.
image

I’m afraid I might create an infinite loop by trying to collect these sub boms part numbers.
Maybe someone can guide me on the way how I can loop through these sub boms?

We did something like this using a customization on MES, in the “Start Production Activity” screen. We basically have a BAQ to identify all the parts in all the BOMs in the tree, then we use the dynamic query adapter to pull that BAQ.

If you search this forum for dynamic query you’ll find dozens fo examples for how to use it.