Announcement

Collapse
No announcement yet.

How is this field made

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

  • 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:	452
Size:	8.8 KB
ID:	72945

  • #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


    • #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


      • #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


        • #5
          Need to set columnAttributeMap

          Comment

          Working...
          X