Forum Discussion

sudhir_sbevision_com's avatar
11 hours ago

Programmatically add Item types to Poly type

Hello Experts

We use a Poly Item type (call it Repo_Poly) to manage relation and some metadata between and a single source Itemtype to multiple Itemtypes in Aras

We wrote a "Action" for Admins to add the Itemtypes to our "Repo_Poly" type to help with usability as we do other things in the background after adding the new type.

Our Server method does the following

  • Add a Morphae relation between the Poly type and selected Itemtype
  • Add custom actions on selected Itemtype

The thing to note is, this seems to add the Itemtype to Poly type but it does not seem to update the "List" which is used to managed Poly type. 

But when we create the relations which exists between our source type and poly type(Repo_Poly), the items under the relationship table are being shown as Restricted

 

The DB entries seems to be identical for types added manually or programmatically

As a test we set World permission on all the types involved but we still see the same error.

We are unable to figure out what is missing, we are also unable to trigger the "beforesave" and "after save" events on the Poly type.

We also tried adding the selected Item type to this "List" used by the Poly type but there was no change.

Any suggestions will be highly appreciated

 

3 Replies

  • Did you add the server events that every PolyItem Type uses? The 8 internal Methods?

    • sudhir_sbevision_com's avatar
      sudhir_sbevision_com
      Ideator III

      We did not add any server events on any types, the OOTB events already exist on our Poly type.

      Is there anything else we need to do?

      • mconstantin_aras_com's avatar
        mconstantin_aras_com
        Creator II

        Hi,

        Just to make sure I understand correctly:

        1. You trigger an Action.
        2. The Action calls a server Method.
        3. The Method adds an ItemType as a Poly Source to your Poly ItemType.

        If that's the case, a few things come to mind.

        First, adding an ItemType to the Poly Sources relationship programmatically does not necessarily execute all of the logic that is triggered when the same operation is performed through the standard ItemType editor.

        Some server events or internal framework logic may be skipped, which can lead to unexpected results even though the resulting database records appear identical.

        May I ask what the purpose is behind having an action for administrators to add ItemTypes as Poly Sources?

        For example, is the method also creating properties, relationships, or other configuration that links the Poly ItemType to the newly added source ItemType?

        As you may know, properties defined on a Poly ItemType are expected to be available on the ItemTypes used as Poly Sources. Is your method also creating or validating those properties? If that logic is normally performed when configuring the Poly Source manually, it may be getting skipped when the relationship is created programmatically.

        Regarding the "Restricted" entries, from my experience the most common causes are:

        • The current user does not have permission to discover or get the referenced item.
        • The related item cannot be resolved correctly, even though the relationship record exists (for example, an incorrect related_id).

        Since you mentioned that the database entries are identical and that assigning World permissions did not help, I would investigate whether an additional metadata refresh, cache refresh, or server restart is required after adding the Poly Source relationship programmatically.

        If you manually add the same ItemType as a Poly Source, save it, and then compare the resulting records (including any related metadata tables) with the programmatically created version, do you see any differences at all?