Forum Discussion

Former_Member's avatar
Former_Member
Accelerator III
9 years ago

get the higher item in a product structure based on several ItemTypes

Hi Community, I don't understand what methods like getRelationships or getParentItem() do as I always get the same error when I use it: "Object reference not set to an instance of an object." What type of data is returned by these methods? I am looking for a way to go up in a product structure built using several ItemTypes (not like the standard solution where all is based on the "Part" ItemType with its class structure, in my case classes are made with ItemTypes). the structure is made like this: Part---partInstance--->Assy---AssyInstance--->Assy---AssyInstance--->Root How to go up until Root from a server event running on partInstance? Best regards, Camille

7 Replies

  • Hi Camille, I believe you will need to write a recurring function which from the selected part will go up in the structure, looking for relationships, which have the selected item as "related_id". Let us know if you need some assistance to try something. I can look into it. Give us some more detail on your datamodel.
  • Hi Yoann, There is two types of instances in my datamodel, relative and absolute. The relative instance is the link between the part and its father product, the absolute instance is the link between the part and the main referential (root). To create the relative instance I use the standard behavior of Aras as I just have to add a part to an assembly. A server event on the part instance will create the absolute instance. It needs to identify if the father assembly is connected directly or not to the root, return an error if no root or if it is not connected to a root, open a search dialog if several roots exists, create the absolute instance once all is ok. Did you ever succeed to use getParentItem() method? I cannot get it working on my side. I could workaround with getRelationships but it never returns me the right itemtype, I know I am missing something. Best regards, Camille
  • the getParentItem() methods is just looking for a parent Item in the DOM object manipulated. If you didn't fetch the parent item from the server you will not get it. It doesn't make a query to the database. from an item , if you want the parent, you need to run a full query saying: Item Rel = this.newItem("MyRelationship"); Rel.setProperty("related_id",MyItemId); Rel = Rel.apply(); You should get all the parent relationships and so if you look for the source_id you will get the parent parts. makes sense?
  • Many thanks for your help Yoann! That's it, I read the documentation for weeks but cannot firgure out the use of newItem. Intuitively, when I read this code, I see you creating an item of type MyRelationship then setting the related_id to the value contained in MyItemId. But, tell me if I understand it well, what you do is to look for relationships of type MyRelationship whose related_id is MyItemId? So the relationship I am looking for will be contained in Rel?
  • the code is actually : Item Rel = this.newItem(“MyRelationship”,"get"); Rel.setProperty(“related_id”,MyItemId); Rel = Rel.apply(); I was missing the "get" action . Yes, it does look for the relationships. And yes the Rel object will contain the relationships (you need to look at their source_id property to find the parent).      
  • What is returned if the relationship I am looking for doesn't exist? The parent Assembly of the part instance (of which creation starts the method) can be linked to the next Assembly with 3 types of relationships. I don't know if it is the proper way but I am trying to do it with a if for each type