How can I programatically add a custom field to a Layout?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • safwanyp
    Junior Member
    • Feb 2025
    • 2

    How can I programatically add a custom field to a Layout?

    Hello everyone!

    I'm a new Espo user and developer. I've been exploring the creation of extensions and i'm stuck on one particular issue. I am using the Espo `ext-template` repository as a starter. I can install my extension with no issues and things work well, except for adding my custom field to a layout automatically on installation.

    For some context, all I'm doing in my extension is the following:
    - Create a new field called `example` in the `Account` entity (custom/Espo/Modules/ExampleExt/Resources/metadata/entityDefs/Account.json)
    - Have some localised values for the field (custom/Espo/Modules/ExampleExt/Resources/i18n/{locale}/Account.json)

    With this setup, I have to manually add the field to Account's Details layout. I want my extension to do it instead, so that it's added when installed, and removed when uninstalled.

    So far, I have tried the following:
    - Add it to the Layout through the GUI
    - Copy the changes in custom/Espo/Custom/Resources/layouts/Account/detail.json and paste them in my extension at custom/Espo/Modules/ExampleExt/Resources/metadata/layouts/Account/detail.json

    But this does not seem to work. Is there something I'm missing?

    Thank you!
  • yuri
    Member
    • Mar 2014
    • 8645

    #2
    Hi,

    There's no an API for this action. But you can rewrite the custom layout JSON file programmatically. You can add a new panel with your fields.
    If you find EspoCRM good, we would greatly appreciate if you could give the project a star on GitHub. We believe our work truly deserves more recognition. Thanks.

    Comment

    • safwanyp
      Junior Member
      • Feb 2025
      • 2

      #3
      Hey yuri,

      Thanks for that reply! I'll look for something in the docs for this then!

      Comment

      • radek
        Junior Member
        • Feb 2024
        • 10

        #4
        Hi,

        Metadata in custom overwrite Metadata from modules (not in all cases, but in case of layouts they do).

        Make sure to remove your json layout from custom when you copy it over to extension.

        Then check your extension's order - https://docs.espocrm.com/development/modules/#order

        Set it to a higher number if you think it is not applying.

        Lastly, Metadata get cached. If cache is enabled you must rebuild after changing Metadata, or disable cache in administration and refresh the page on every change.

        Hope this helps

        Comment

        Working...