Hi,
I need to find the sequences child-father in this table starting with an input id. For example 1-3-9-11-18 or 2-5-6-15-20. I tried using query in forEach loop but without success. Do you have any suggestions about it?
Discussion posts and replies are publicly visible
You can achieve it using recursion. You will have to create two rules. Please find the code blocks of them below.
Name - HS_rule2
a!localVariables( local!nextId: displayvalue( ri!id, ri!data.id, ri!data.idFather, null ), if( a!isNullOrEmpty(local!nextId), {}, { local!nextId, rule!HS_rule2( id: local!nextId, data: ri!data ) } ) )
Rule inputs - id (Number (Integer)) & data (Any Type)
Now its parent interface. Name - HS_rule1
a!localVariables( local!id: 10, local!data: { { id: 1, idFather: 3 }, { id: 2, idFather: 5 }, { id: 3, idFather: 9 }, { id: 5, idFather: 6 } }, if( contains(tointeger(local!data.id),local!id), { local!id, rule!HS_rule2(id: local!id, data: local!data) }, null ) )
Change the value of local!id with whatever you want to search and paste your dictionary/CDT in local!data
This will give you a list of all the IDs that are inter-related, in sequential order. Hope that helps!
That's perfect Harshit! Many thanks
I hope your chains are not long! Recursion can quickly become a resource hog.
Yes, Stephan, the chains are max 5 steps deep.