<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://community.appian.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Find sequences child-father in a table</title><link>https://community.appian.com/discussions/f/rules/29080/find-sequences-child-father-in-a-table</link><description>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 
 
 </description><dc:language>en-US</dc:language><generator>Telligent Community 12</generator><item><title>RE: Find sequences child-father in a table</title><link>https://community.appian.com/thread/115026?ContentTypeID=1</link><pubDate>Mon, 26 Jun 2023 09:15:54 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:39b627d7-f83c-4116-8eec-15c9df38880b</guid><dc:creator>katafina1470</dc:creator><description>&lt;p&gt;Yes, Stephan, the chains are max 5 steps deep.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Find sequences child-father in a table</title><link>https://community.appian.com/thread/114850?ContentTypeID=1</link><pubDate>Thu, 22 Jun 2023 18:30:22 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:abafacb5-7576-4ef4-b0d1-b5f7b7e5a09d</guid><dc:creator>Stefan Helzle</dc:creator><description>&lt;p&gt;I hope your chains are not long! Recursion can quickly become a resource hog.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Find sequences child-father in a table</title><link>https://community.appian.com/thread/114848?ContentTypeID=1</link><pubDate>Thu, 22 Jun 2023 18:12:31 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:8f74b1f4-ee4d-49e3-9ab3-0f3cec021584</guid><dc:creator>katafina1470</dc:creator><description>&lt;p&gt;That&amp;#39;s perfect Harshit! Many thanks&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Find sequences child-father in a table</title><link>https://community.appian.com/thread/114846?ContentTypeID=1</link><pubDate>Thu, 22 Jun 2023 17:32:54 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:508aef95-4083-47d9-94d5-403d5b50b418</guid><dc:creator>Harshit Bumb (Appyzie)</dc:creator><description>&lt;p&gt;You can achieve it using recursion. You will have to create two rules. Please find the code blocks of them below.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Name - HS_rule2&lt;br /&gt;&lt;pre class="ui-code" data-mode="text"&gt;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
      )
    }
  )
)&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Rule inputs -&amp;nbsp;id (Number (Integer)) &amp;amp;&amp;nbsp;data (Any Type)&lt;/p&gt;
&lt;p&gt;Now its parent interface.&amp;nbsp;&lt;br /&gt;Name -&amp;nbsp;HS_rule1&lt;br /&gt;&lt;pre class="ui-code" data-mode="text"&gt;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
  )
  
)&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Change the value of local!id with whatever you want to search and paste your dictionary/CDT in local!data&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;This will give you a list of all the IDs that are inter-related, in sequential order. Hope that helps!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>