<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://www.aras.com/community/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>How to get parent Item type recursively</title><link>https://www.aras.com/community/f/development/3260/how-to-get-parent-item-type-recursively</link><description>I have structure where, I have to find all the parent Item in my BOM tree, so How to find it by aml query, or  any server side method for finding all parent Item in BOM.</description><dc:language>ja-JP</dc:language><generator>Telligent Community 12</generator><item><title>RE: How to get parent Item type recursively</title><link>https://www.aras.com/community/thread/11240?ContentTypeID=1</link><pubDate>Wed, 18 Jun 2025 04:55:16 GMT</pubDate><guid isPermaLink="false">916d3f7e-8ddc-42f8-8d45-380822f51406:d8c061e8-1846-4fce-8c2f-8c617cce03dd</guid><dc:creator>TU_YINING</dc:creator><description>&lt;p&gt;Here is a sample for recursive search for forward and backward.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="csharp"&gt;////////////////////////////////////////////////////////////////////
///   - IN:
///     - RequestState
///     - [String] initIDs: initial IDs (csv)
///     - Properties
///     - [String] direction: forward/backward
///     - [String] itemtype: itemtype&amp;#39;s name of RELATIONSHIP
///     - [String] is_all_level: return all levels or only the top/end
///       - 0(default): top/end only
///       - 1: all levels (all children or all parents)
///   - OUT:
///   - RequestState
///     - [String] returnIDs: target IDs (csv)
///   - newResult()
///     - 0   : normal
///     - E003: Bad Args
///     - E004: No target Items
///
////////////////////////////////////////////////////////////////////

Innovator inn = this.getInnovator();
List&amp;lt;string&amp;gt; targetList;
string direction, itemtype;

try
{
  string temp = (string)RequestState[&amp;quot;initIDs&amp;quot;];
  targetList = temp.Split(&amp;#39;,&amp;#39;).ToList();
  RequestState.Remove(&amp;quot;initIDs&amp;quot;);
}
catch (Exception e)
{
  return inn.newResult(&amp;quot;E004&amp;quot;);
}

try
{
  direction = this.getProperty(&amp;quot;direction&amp;quot;);
  itemtype = this.getProperty(&amp;quot;itemtype&amp;quot;);
  if (direction != &amp;quot;forward&amp;quot; &amp;amp;&amp;amp; direction != &amp;quot;backward&amp;quot;)
  {
    throw new Exception(&amp;quot;Unvalid parameter.&amp;quot;);
  }
}
catch (Exception e)
{
  return inn.newResult(&amp;quot;E003&amp;quot;);
}

var relatedList = new List&amp;lt;string&amp;gt;();

var libraryList = new List&amp;lt;string&amp;gt;();

try
{
  while (targetList.Count != 0)
  {
    for (int i = targetList.Count - 1; i &amp;gt;= 0; i--)
    {
      if (libraryList.Contains(targetList[i]) == false)
      {
        Item sourceItem = inn.newItem(itemtype, &amp;quot;get&amp;quot;);
        sourceItem.setAttribute(&amp;quot;select&amp;quot;, direction == &amp;quot;forward&amp;quot; ? &amp;quot;related_id&amp;quot; : &amp;quot;source_id&amp;quot;);
        sourceItem.setProperty(direction == &amp;quot;forward&amp;quot; ? &amp;quot;source_id&amp;quot; : &amp;quot;related_id&amp;quot;, targetList[i]);
        Item rtItem = sourceItem.apply();
        int rtCount = rtItem.getItemCount();
        if (rtCount == 0)
        {
          relatedList.Add(targetList[i]);
        }
        else
        {
          for (int j = 0; j &amp;lt; rtCount; j++)
          {
            Item resultItem = rtItem.getItemByIndex(j);
            targetList.Add(resultItem.getProperty(direction == &amp;quot;forward&amp;quot; ? &amp;quot;related_id&amp;quot; : &amp;quot;source_id&amp;quot;));
          }
        }
        libraryList.Add(targetList[i]);
      }
      targetList.RemoveAt(i);
    }
  }
}
catch (Exception e)
{
  // unknown Relationship itemtype
  return inn.newResult(&amp;quot;E003&amp;quot;);
}

if (this.getProperty(&amp;quot;is_all_level&amp;quot;) == &amp;quot;1&amp;quot;)
{
  RequestState.Add(&amp;quot;returnIDs&amp;quot;, String.Join(&amp;quot;,&amp;quot;, libraryList));
}
else
{
  RequestState.Add(&amp;quot;returnIDs&amp;quot;, String.Join(&amp;quot;,&amp;quot;, relatedList));
}
return inn.newResult(&amp;quot;0&amp;quot;);&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to get parent Item type recursively</title><link>https://www.aras.com/community/thread/11238?ContentTypeID=1</link><pubDate>Tue, 17 Jun 2025 06:33:41 GMT</pubDate><guid isPermaLink="false">916d3f7e-8ddc-42f8-8d45-380822f51406:40e4e9b3-3526-4759-941e-ce6d43ed15b1</guid><dc:creator>Ananta Jena</dc:creator><description>&lt;p&gt;Hi &lt;a href="/community/members/tu_5f00_yining"&gt;TU_YINING&lt;/a&gt;&amp;nbsp;&lt;a href="/community/members/angela"&gt;AngelaIp&lt;/a&gt;&amp;nbsp;Could you please help me how to find this? Advance Thanks...&lt;br /&gt;Recursive parent...&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to get parent Item type recursively</title><link>https://www.aras.com/community/thread/6219?ContentTypeID=1</link><pubDate>Fri, 08 Jan 2021 07:43:46 GMT</pubDate><guid isPermaLink="false">916d3f7e-8ddc-42f8-8d45-380822f51406:f625ffba-fa4e-426f-b34c-27b242f90ba1</guid><dc:creator>TU_YINING</dc:creator><description>&lt;p&gt;I&amp;#39;ve tried this and it doesn&amp;#39;t repeat since you put the fix id to the related_id&amp;#39;s Item. It always do one level I think.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to get parent Item type recursively</title><link>https://www.aras.com/community/thread/513?ContentTypeID=1</link><pubDate>Fri, 02 Jun 2017 03:21:49 GMT</pubDate><guid isPermaLink="false">916d3f7e-8ddc-42f8-8d45-380822f51406:4d8cc0e2-ed84-4674-9cef-d848b64dad0b</guid><dc:creator>Former Member</dc:creator><description>Hi Maddy,

As I understood your query, your are trying to do reverse operation using GetItemRepeateconfig.

You can try below AML then,

&amp;lt;AML&amp;gt;
&amp;lt;Item type=&amp;quot;Part BOM&amp;quot; action=&amp;quot;get&amp;quot; repeatProp=&amp;quot;source_id&amp;quot; repeatTimes=&amp;quot;2&amp;quot; select=&amp;quot;source_id(name)&amp;quot; &amp;gt;
&amp;lt;related_id&amp;gt;
&amp;lt;Item type=&amp;quot;Part&amp;quot; action=&amp;quot;GetItemRepeatConfig&amp;quot; select=&amp;quot;name&amp;quot; id=&amp;quot;{your bom part id}&amp;quot;&amp;gt;&amp;lt;/Item&amp;gt;
&amp;lt;/related_id&amp;gt;
&amp;lt;/Item&amp;gt;
&amp;lt;/AML&amp;gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to get parent Item type recursively</title><link>https://www.aras.com/community/thread/483?ContentTypeID=1</link><pubDate>Tue, 23 May 2017 03:18:45 GMT</pubDate><guid isPermaLink="false">916d3f7e-8ddc-42f8-8d45-380822f51406:beb35bc4-9cef-4b80-a03e-9f8346699608</guid><dc:creator>Maddy</dc:creator><description>Actually I write AML query for getting all parent item.

In my bom tree I want parent Items (with all properties). i.e I run AML query on item which is at 2nd level in bom, so I want Its parent and Parent&amp;#39;s parent (with all) property. Is there any reverse method to do this?&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to get parent Item type recursively</title><link>https://www.aras.com/community/thread/428?ContentTypeID=1</link><pubDate>Mon, 08 May 2017 12:23:32 GMT</pubDate><guid isPermaLink="false">916d3f7e-8ddc-42f8-8d45-380822f51406:de71fcab-18b6-455f-80b9-dbda9b65b287</guid><dc:creator>Yoann Maingon</dc:creator><description>Look at the very nice Erik Domke&amp;#39;s documentation (hoping it will or maybe it has been migrated to github already)

&lt;a href="https://amlstudio.codeplex.com/wikipage?title=Get%20Where%20Used%20Data&amp;amp;referringTitle=Documentation"&gt;amlstudio.codeplex.com/wikipage&lt;/a&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>