Find sequences child-father in a table

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? 

id idFather
1 3
2 5
3 9
5 6
6 15
9 11
11 18
15 20

  Discussion posts and replies are publicly visible

Parents
  • 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!

Reply Children