Announcement

Collapse
No announcement yet.

Layouts - How can I add a side panel that displays Related Entity

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Layouts - How can I add a side panel that displays Related Entity

    I can see that you can add a Bottom Panel when there is a One-to-Many or Many-to-Many relationship to the Left Entity in the Relationship Definition.

    What I am trying to achieve is the display of a Bottom or Side Panel in the Detail View for a related entity where there is a One-to-One relationship.

    As an Example, let's say there are two Entities:

    EntityAlpha
    EntityBeta

    EntityAlpha has a One-to-One-Left relationship with EntityBeta.
    There is NOT always an EntityAlpha record for every EntityBeta.

    On the Detail Layout of EntityBeta, I would like to display a Bottom or Side Panel containing the fields in EntityAlpha, when there is a related record in EntityAlpha.

    I know that I can create Layouts for EntityAlpha (both Detail and Side Panels). By default, these panels are not selectable in the Layouts of EntityBeta unless it is a Many-to-Many or One-to-Many relationship.

    Any advice in this will be greatly appreciated.

  • #2
    perhaps this helps: https://forum.espocrm.com/forum/deve...n-a-side-panel

    Comment


    • #3
      Thank you, that tutorial is helpful as a starting point for my needs.

      However, I have come across a problem that perhaps someone can guide me about.

      I am developing a custom Module for a client.

      The code for my Module is located within the two custom Module folders, as recommended by the Docs:

      Code:
      <espo-root>/custom/Espo/Modules/<MyModule>
      <espo-root>/client/custom/module/my-module
      Continuing with the example I gave above, EntityAlpha is a custom entity that I have defined within my custom module in:

      Code:
      <espo-root>/custom/Espo/Modules/<MyModule>/Resources/metadata/entityDefs
      <espo-root>/custom/Espo/Modules/<MyModule>/Resources/metadata/clientDefs
      ​​
      ...and the other folders

      However, EntityBeta is a custom entity defined and managed by the client using the GUI Admin, so all the definitions for EntityBeta are in:

      Code:
      <espo-root>/custom/Espo/Custom/Resources/metadata/entityDefs
      <espo-root>/custom/Espo/Custom/Resources/metadata/clientDefs

      I would like to keep the definitions and code for the new side-panel for EntityBeta within my module, so that if the module is removed in the future, the side-panel is removed along with EntityAlpha as part of the module.

      However, it seems that when the `clientDefs` are merged recursively, the definitions in the Custom folder come after the Module folder. This can be inferred from the documentation on this page as well.

      When I do this:

      file: <espo-root>/custom/Espo/Modules/<MyModule>/Resources/metadata/clientDefs/EntityBeta.json
      Code:
      "sidePanels": {
        "detail": [
          "__APPEND__",
          {
            "name": "entityalpha",
            "label": "Entity Alpha",
            "view": "my-module:views/side-panels/entity-alpha-side-panel",
            "aclScope": "EntityAlpha"
          }
        ]
      }​
      The append doesn't work, since the definitions in the Custom/Resources folder overwrite. The Append is needed in those definitions. But since I am NOT able to manage those definitions, I cannot ensure that an __APPEND__ stays in there.

      The Question:
      Is there a way to have the definitions in my module get appended to the definitions in the Custom/Resources folder without having access to the definitions in that folder?

      Comment


      • #4
        You can try this, create a layouts.json under your custom/Espo/Modules/YourModule/Resources/metadata/app (This would tell the system which layout to use as default) and paste the code below for your Entitybeta

        PHP Code:
        {
            
        "Entitybeta": {
                
        "detail": {
                    
        "module""YourModule"
                
        }
            }
        }
        ​ 

        Notice that you can define which layout type should be defaulted to the one under your module e.g detail under your module, then define the layout under layouts in your module as you did above.

        PHP Code:
        {
            
        "sidePanels": {
                
        "detail": [
                    
        "__APPEND__",
                    {
                        
        "name""entityalpha",
                        
        "label""Entity Alpha",
                        
        "view""my-module:views/side-panels/entity-alpha-side-panel",
                        
        "aclScope""EntityAlpha"
                    
        }
                ]
            }
        }
        ​ 

        PLEASE NOTE THAT YOU HAVE TO DEFINE THE WHOLE DETAIL LAYOUT not just the sidePanels part. So you might want to copy the current detail layout in the custom folder made by your client and add to it the sidePanel then use it in your module.

        Hope this helps
        Rabii
        Web Dev

        Comment


        • aldisa
          aldisa commented
          Editing a comment
          Thanks for the suggestion. I will try this approach and see if it solves my needs.

      • #5
        To display a side or bottom panel for a related entity in a One-to-One relationship, such as showing fields from EntityAlpha on the detail view of EntityBeta, you can utilize a custom layout or scripting solution. Since standard layout options may not allow direct selection of EntityAlpha in EntityBeta, you can create a conditional display using the entity's relationship logic. This typically involves adding a custom field in EntityBeta that fetches related data from EntityAlpha and displays it in a side or bottom panel. Check if your platform allows custom field definitions or conditional visibility settings in the layout configuration to implement this effectively.

        Comment

        Working...
        X