AnsweredAssumed Answered

Applying a custom filter when opening a drawer.

Question asked by Matthew Lewis on Jul 28, 2017
Latest reply on Aug 1, 2017 by Matthew Lewis

When viewing a Contact record, there is a subpanel called "Sites", listing Sites that the Contact is related to. I've been attempting to add an initial filter to the results of the drawer that appears when selecting the "Link Existing Record" option, to show only those Sites which are linked to the Account to which the Contact is also linked.

 

Following the filtering guides given here, I've managed to add a filter in .custom/Extension/modules/Sites/Ext/clients/base/filters/basic/FilterByAccountTemplate.php, which looks like this:

 

<?php

$viewdefs['Sites']['base']['filter']['basic']['filters'][] = array(
     'id' => 'FilterByAccountTemplate',
     'name' => 'LBL_FILTER_BY_ACCOUNT_TEMPLATE',
     'filter_definition' => array(
          array(
               <Linking Field> => array(
                    '$equals' => ''
               )
          )
     ),
     'editable' => true,
     'is_template' => true
);

 

And a display label in .custom/Extension/modules/Sites/Ext/Language/en_us.FilterByAccountTemplate.php, which looks like this:

 

<?php

$mod_strings['LBL_FILTER_BY_ACCOUNT_TEMPLATE'] = 'Account Sites';

 

So far, this is functional. When I post filter options to the right URL (e.g. https://<My Site>/rest/v10/Sites?<snip>&filter%5B0%5D%5B<Linking Field>%5D%5B%24equals%5D=<Account ID>), I'm getting back the right results.

 

But when I try to apply the filter in the GUI, no request is made; I'm simply getting all records returned, rather than filtered records. The filter displays correctly, and appears when the drawer is opened, but does not apply. My code for the front-end is in .custom/Modules/Sites/clients/base/fields/link-action/link-action.js, and looks like this:

 

({
    extendsFrom: 'LinkActionField',

    initialize: function(options) {
        this._super('initialize', [options]);
    },

    openSelectDrawer: function() {
        if (this.isDisabled()) {
            return;
        }
        var parentModel = this.context.get('parentModel');
     var linkModule = this.context.get('module');
        var link = this.context.get('link');
        var filterOptions = new app.utils.FilterOptions()
            .config({
                'initial_filter': 'FilterByAccountTemplate',
                'initial_filter_label': 'LBL_FILTER_BY_ACCOUNT_TEMPLATE',
                'filter_populate': {
                    '<Linking Field>': parentModel.get('account_id'),
                }
            })
            .format();
        var context = {
            module: linkModule,
            recParentModel: parentModel,
            recLink: link,
            recContext: this.context,
            recView: this.view,
            filterOptions: filterOptions
        }
        app.drawer.open({
            layout: 'multi-selection-list-link',
            context: context,
        });
    }
})

 

What am I doing wrong here? I've tried fiddling about with it and all I seem to get back is nothing. Applying and removing the filter doesn't make the client send any requests to the server.

Outcomes