This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

DEVELOPERS FORUM - How to get parent item from child item.

Manali - Tuesday, July 15, 2014 5:39 AM:

I have child item number and i want to find out its parent item number.

 

Thanks,

Manali



zahar - Tuesday, July 15, 2014 5:54 AM:

<AML>

  <Item type="Part" action="get">

  <Relationships>

  <Item type="Part BOM" action="get">

  <related_id>

  <Item type="Part" action="get">

  <item_number>XXXXXX</item_number>

  </Item>

  </related_id>

  </Item>

  </Relationships>

  </Item>

</AML>



eknath - Thursday, March 24, 2016 4:57 AM:

Hi Zahar, How can i get parent item from child item using c sharp method.

zahar - Thursday, March 24, 2016 7:18 AM:

I assume that:

  1. you are running this code from Aras method
  2. you are talking about Part BOM relationship between 2 parts

Your code will be like this:

Item qry = this.getInnovator().newItem("Part", "get");
Item bomRelItm = qry.createRelationship("Part BOM", "get");
Item childItem = bomRelItm.createRelatedItem("Part", "get"); 
childItem.setProperty("item_number", "xxxxxxx");
qry  = qry.apply();

if (!qry.isError()) {
      for (int i = 0; i < qry.getItemCount(); i++) {
          Item parentItem =qry.getItemByIndex(i);
    }

 

 

Lines 1-5 you can replace with

Item qry = this.getInnovator().applyAML(MYXMLFROMPREVIOUSANSWER);