Announcement

Collapse
No announcement yet.

filter link field values by other entity link field

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

  • filter link field values by other entity link field

    Assuming for a custom entity I want to only allow to select/add contacts (hasMany link) for an specific account the user selected in another link field (account). Would it possible to filter the link by a subquery using values from another field?

  • #2
    Do you want something like entity Case works? (after selecting account, you can select only contacts, related to this account)

    Comment


    • #3
      This would be a compromise. The contact control in Case is not filtered in the auto complete but at least when you klick on the select button the simple search is already filtered by the selected account. I will check how this is implemented.
      The users would expect that the auto complete would be filtered the same way.

      Comment


      • #4
        Now I tried to create a custom view for my custom entity Contract as:
        ./client/custom/src/views/contract/fields/contact.js
        Code:
        Espo.define('views/contract/fields/contact', 'views/fields/link', function (Dep) {
        
            return Dep.extend({
        
                getSelectFilters: function () {
                    if (this.model.get('accountId')) {
                        return {
                            'account': {
                                type: 'equals',
                                field: 'accountId',
                                value: this.model.get('accountId'),
                                valueName: this.model.get('accountName'),
                            }
                        };
                    }
                },
        
                getCreateAttributes: function () {
                    if (this.model.get('accountId')) {
                        return {
                            accountId: this.model.get('accountId'),
                            accountName: this.model.get('accountName')
                        }
                    }
                }
        
            });
        
        });
        and in Custom/Resources/metadata/entityDefs/Contract.json I set
        Code:
                "contact": {
                    "type": "link",
                    "view": "views/contract/fields/contact"
                },
        unfortunately the filter is not beeing used. How do I have to register a custom view? Maybe my path or definition is not correct?

        Thanks!

        Comment


        • #5
          Right view is 'custom:views/contract/fields/contact'. Fix it in both of files

          Comment


          • #6
            Thanks, that was the tirck. I already tried /moduel/view but without success. At the same time I found the right syntax in https://github.com/espocrm/documenta...ustom-views.md. Shame on me ...

            Comment


            • #7
              I got the filter in the dialog to work, but did you find a solution for filtering the results in the autocomplete?
              I agree that not having the autocomplete filtered is a potential gotcha for the users.

              Comment


              • #8
                OK I think I got it.
                a) Create a Class of the AutoComplete to be Filtered in custom/Espo/Custom/SelectManagers/[YourEntityToBeFiltered].php

                b) created a function like protected function filterAssignable(&$result) (see filterActive in application/Espo/SelectManagers/User.php as an example) Mine looked like this:

                protected function filterAssignable(&$result)
                {
                $result['whereClause'][] = array(
                'assign_status' => 'assignable',
                );
                }
                c) in the custom field view definition like above add the function (in my case 'assignable'):
                getSelectPrimaryFilterName: function () {
                return 'assignable';
                }

                So now with Hi-Ko's filtering of the dialog and this filtering of the autocomplete it's harder for users to pick the wrong thing...

                Hope that helps someone else.


                Comment

                Working...
                X