EspoCRM 8.4: Filter Link Field Options in Dynamic Handler Not Working

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • keithritherus
    Junior Member
    • Oct 2025
    • 6

    #1

    EspoCRM 8.4: Filter Link Field Options in Dynamic Handler Not Working

    Problem Summary


    I'm trying to implement dynamic filtering for a Wallet field in TopUp entity based on the selected Account. When a user selects an Account, the Wallet field should only show wallets that belong to that account. Current Setup
    • EspoCRM Version: 8.4 (Docker)
    • Entity: TopUp with fields accountId (link to Account) and walletId (link to Wallet)
    • Relationship: Wallet belongs to Account via accountId field
    • Implementation: Dynamic Handler in top-up-dynamic-handler.js
    What I've Tried
    • Dynamic Handler with selectFilterData:
    Code:
    walletView.selectFilterData = {
        whereAdditional: [{
            type: 'equals',
            attribute: 'accountId',
            value: accountId
        }]
    };
    • Override actionSelect method:
    Code:
    walletView.actionSelect = function() {
        var options = {
            scope: 'Wallet',
            multiple: false,
            whereAdditional: [{
                type: 'equals',
                attribute: 'accountId',
                value: accountId
            }]
        };
        // Create modal with options...
    };
    • Global AJAX hooks (jQuery, Fetch, XHR) to modify API requests
    Current Status
    • Dynamic handler loads successfully ✅
    • Account change detection works ✅
    • Wallet field found ✅
    • Filter applied in modal options ✅
    • BUT: API request still shows unfiltered URL: http://localhost:8080/api/v1/Wallet?...2CbalanceAmoun t%2Cname%2Cname&maxSize=10&offset=0&orderBy=&order =
    Expected Result


    API request should include whereAdditional parameter: http://localhost:8080/api/v1/Wallet?...ereAdditional=[{"type":"equals","attribute":"accountId","value ":" 659620fee3422dd94"}] Files to Share

    Questions
    1. What's the correct way to apply whereAdditional filters to link field selections in EspoCRM 8.4?
    2. Why doesn't the modal's whereAdditional option translate to API request parameters?
    3. Is there a better approach than overriding actionSelect for this use case?
    Additional Context
    • The handler successfully detects account changes
    • Modal creation works with correct options
    • All console logs show expected values
    • Only the final API request lacks the filter parameter
    Attached Files
  • rabii
    Active Community Member
    • Jun 2016
    • 1321

    #2
    Hey depending on relationship you have between Wallet and TopUp entities you can use select handlers as it will much suitable for your case. So you can use this one below which check if the current we have an account on the ToUp then apply same account in filtering the wallet.

    No if you have a one to many between ToUp and Walett (One toup has many wallets) => then define this handler in the relationship on clientdefs of the toup



    If you have a has one relationship then use



    below handler code

    PHP Code:
    define('custom:handlers/shared-account-select-related', ['handlers/select-related'], function (SelectRelatedHandler) {

        return 
    SelectRelatedHandler.extend({

            
    /**
             * @param {module:model} model
             * @return {Promise<module:handlers/select-related~filters>}
             */
            
    getFilters: function (model) {
                
    let advanced = {};

                
    let accountId null;
                
    let accountName null;

                if (
    model.get('accountId')) {
                    
    accountId model.get('accountId');
                    
    accountName model.get('accountName');
                }

                if (
    accountId) {
                    
    advanced.account = {
                        
    attribute'accountId',
                        
    type'equals',
                        
    valueaccountId,
                        
    data: {
                            
    type'is',
                            
    nameValueaccountName
                        
    }
                    };
                }

                return 
    Promise.resolve({
                    
    advancedadvanced
                
    });
            }
        });
    }); 

    Also make sure that account link is has correct name if you use anything different then account as name please amend the code.

    I hope this helps
    Rabii
    say hey

    Comment

    • rabii
      Active Community Member
      • Jun 2016
      • 1321

      #3
      I have just checked the files you attached and from the clientDefs of ToUP seems you don't have a relationship between toup and wallet (if this is the case then you can use alternative method) a custom view for the wallet link field - create a custom view for the wallet field on topup and assign it to the wallet view

      if your entityDefs (ToUp)

      PHP Code:
      {
          
      "fields": {
              
      "wallet": {
                  
      "type""link",
                  
      "view""custom:views/topup/fields/wallet"
              
      }
          }
      }
      ​ 

      and below the code for the wallet link field view

      PHP Code:
      define('custom:views/topup/fields/wallet', ['views/fields/link'], function (LinkFieldView) {

          return 
      LinkFieldView.extend({

              
      getSelectFilters: function () {
                  if (
      this.model.get('accountId')) {
                      return {
                          
      'account': {
                              
      type'equals',
                              
      attribute'accountId',
                              
      valuethis.model.get('accountId'),
                              
      data: {
                                  
      type'is',
                                  
      nameValuethis.model.get('accountName'),
                              },
                          }
                      };
                  }
              },

          });
      });
      ​​ 
      Rabii
      say hey

      Comment

      • keithritherus
        Junior Member
        • Oct 2025
        • 6

        #4
        Thanks rabii, you saved my day.

        Comment


        • rabii
          rabii commented
          Editing a comment
          you are welcome
      Working...