Forum Discussion
PART_XCLASS
--> Related Item XCLASS (e.g. class 'Resistor')
I think it´s possible to add the PART_XCLASS relationship with an onBeforeAdd/onAfterAdd Method.angela Hi Angelalp, I was searching the exact same solution and found your answer.
I tried to do this by kick the Method with onBeforeAdd or by AML, but It didn't worked to me.
Do you have any further info on this topic?
my method
[embed:dc8ab71f-3b98-42d9-b0f6-e21e02a0f8e2:bd8bfb92-a7d7-4709-a80b-51156ba3bbe9:type=csharp&text=Innovator%20inn%20%3D%20this.getInnovator%28%29%3B%0D%0Athis.setAction%28%22edit%22%29%3B%0D%0AItem%20xclass%20%3D%20inn.newItem%28%22xClass%22%2C%22get%22%29%3B%0D%0Axclass.setProperty%28%22id%22%2C%22F55659D7906F4E3A89767FEEFF1913C0%22%29%3B%0D%0Axclass%20%3D%20xclass.apply%28%29%3B%0D%0AItem%20rel%20%3D%20this.createRelationship%28%22y_ext_xClass%22%2C%22add%22%29%3B%0D%0Arel.setRelatedItem%28xclass%29%3B%0D%0Areturn%20this%3B]
and I got this
No items of type 'y_ext_xClass' found using the criteria:
<Item type="y_ext_xClass" id="6BFA1DD7EC1B4AB19C7ACAF59AE8C5C8" serverEvents="1" select="*[is_not_null()]" />
- angela1 year agoCatalyst II
Your query in general is a bit confusing :). Your "createRelationship" happens after apply(). And you do the apply() on your xClass item and not at the item you want to edit.
I haven´t tested this one, but I think it worked somehow like this:
this.setAction("edit");
Item xyz_xclass= this.createRelationship("xyz_xClass", "add");
Item xclass= xyz_xclass.createRelatedItem("xClass", "get");
xclass.setProperty("id","123");
Item res = this.apply();But I recommend that you check the official documentation. There is a guide regarding xClasses with many samples.
BTW: If you use thumbnails, I would be happy for additional feedback regarding this topic! Thanks!- Kitty1 year agoIdeator II
Thanks a lot for responding. It works.
[embed:dc8ab71f-3b98-42d9-b0f6-e21e02a0f8e2:5605f47b-3a3d-43b6-a49f-55166b93578f:type=csharp&text=Innovator%20inn%20%3D%20this.getInnovator%28%29%3B%0D%0Athis.setAction%28%22get%22%29%3B%0D%0Athis.setAttribute%28%22levels%22%2C%221%22%29%3B%0D%0AItem%20temp%20%3D%20this.apply%28%29%3B%0D%0AItem%20rel%20%3D%20temp.getRelationships%28%22z_part_xClass%22%29%3B%0D%0Aint%20c%20%3D%20rel.getItemCount%28%29%3B%0D%0Aif%28c%3D%3D0%29%7B%0D%0A%20%20this.setAction%28%22edit%22%29%3B%0D%0A%20%20Item%20xyz_xclass%3D%20this.createRelationship%28%22z_part_xClass%22%2C%20%22add%22%29%3B%0D%0A%20%20Item%20xclass%3D%20xyz_xclass.createRelatedItem%28%22xClass%22%2C%20%22get%22%29%3B%0D%0A%20%20xclass.setProperty%28%22id%22%2C%2282B56E7EC88B4CDA87ABAE435A18D72D%22%29%3B%0D%0A%20%20Item%20res%20%3D%20this.apply%28%29%3B%0D%0A%7D%0D%0A%0D%0Areturn%20this%3B]
I am also looking for a solution to preset it when create a new Item. (My customer want the xClass be selected at beginning)
do you think it works with client method?
BTW: Sorry I don't have answer about your question.