Recursive search?

So, i have a table that is a tree. Every record has a list of children.

Now I want to find the path from a selected element back to the root, resulting in a list of all the parents.

I’m at a bit of a loss as to how to do this? I get that I can recurse with an API workflow but Im not sure how Im supposed to either do a search that doesnt modify or collect the recursive search results?

If the relationship is many to one then you should store a parent on the children records.

1 Like

thanks :wink: This may be obvious, but then how do i collect the chain of parents into a list or RG?

It needs some thinking through as you need to weigh up database design and how you will display the data, and how many layers and records you envisage having.

Off the bat, I would create a list from the child’s parents and keep it going until the childs parent count = 0 and store it to a custom state.

Okau that’s pretty much what I’m trying to do. I’m using a recursive backend call atm and it doesn’t seem to be working,. Can backend calls modify custom states?

How many levels do you have? If it’s not a high number, couldn’t you just set up a regular workflow (not API) and add enough steps to cover the levels you might have?

Well its variable and id rather not build in a limitation.

Ill mess with backend workflows and see if I can figure then out

I have the exact same needs.

I have categories and subcategories. Each is of type ‘Category’, containing a list of ‘Category’ (subcategories). I would need my users to search for a category and get the path from the root category to the searched category.

I really don’t see how to implement a recursive search / workflow… I would need something as : “while parent category is not empty” to build something, but it seems that’s not available, right ?

I have the exact same need…did you ever resolve this? Thanks!!

You can solve this using custom Javascript via the Toolbox plugin