How is this field made

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • shalmaxb
    Senior Member
    • Mar 2015
    • 1606

    How is this field made

    In the demo installation of espoCRM I saw in the entity contacts the multiple link field for accounts. This field has the name link of the account and an enum filed with a role. How can I achive this?
    ​​​​​​​
    Click image for larger version

Name:	accounts.jpg
Views:	481
Size:	8.8 KB
ID:	72945
  • telecastg
    Active Community Member
    • Jun 2018
    • 907

    #2
    Hi shalmaxb ,

    This is how Espo does it:

    The field "role" is actually a field in the "middle table" account_contact which is used to link the entities Account and Contact in a many-to-many relationship
    Click image for larger version  Name:	many_to_many_table.PNG Views:	0 Size:	43.8 KB ID:	72965

    This field ("role") and the other additional field "isInactive" are defined in the Contact.json entityDefs metadata file as "columns" of the field and link "accounts":
    Code:
    {
        "fields": {
            ...        
            "accounts": {
                "type": "linkMultiple",
                "view": "crm:views/contact/fields/accounts",
                "columns": {
                    "role": "contactRole",
                    "isInactive": "contactIsInactive"
                },
                "orderBy": "name"
            },
            ...
        },
        "links": {
            "accounts": {
                "type": "hasMany",
                "entity": "Account",
                "foreign": "contacts",
                "additionalColumns": {
                    "role": {
                        "type": "varchar",
                        "len": 100
                    },
                    "isInactive": {
                        "type": "bool",
                        "default": false
                    }
                },
                "additionalAttributeList": ["columns"],
                "layoutRelationshipsDisabled": true,
                "columnAttributeMap": {
                    "role": "accountRole",
                    "isInactive": "accountIsInactive"
                }
            },
            ....
        }
    }
    and defined in the Account.json entityDefs metadata file "contacts" link like this:
    Code:
    {
        "links" {
            ....
            "contacts": {
                "type": "hasMany",
                "entity": "Contact",
                "foreign": "accounts",
                "columnAttributeMap": {
                    "role": "contactRole",
                    "isInactive": "contactIsInactive"
                }
            },
            ....
        }
    }
    finally, the field is rendered as part of the Contact entity using the field view script client/modules/crm/src/views/contact/fields/accounts.js

    Hope this helps

    Comment

    • esforim
      Active Community Member
      • Jan 2020
      • 2204

      #3
      It been ask a couple of time, myself included but at the end it was still too hard for me. I listed it under section 3.5 of the 'wiki'. But looking at telecastg and the previous post I think this would be the easiest to follow if you want to do it.

      3.5 Require Coding - Related to Entity & Field
      Contribute to o-data/EspoCRM-Learning-and-Design development by creating an account on GitHub.

      Comment

      • krzysztof.czereczon
        Junior Member
        • Aug 2021
        • 3

        #4
        At version 6.1+ something changed, because the configuration of "additionalColumns" from version 5.9.4 is not working right now, the columns that should appear in middle table are append in entity table, somebody knows how to manage this issue?

        Comment

        • yuri
          Member
          • Mar 2014
          • 8453

          #5
          Need to set columnAttributeMap

          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

          Working...