AnsweredAssumed Answered

Custom filter for 'Link Existing Record' not working

Question asked by Steve Rose on Aug 8, 2017
Latest reply on Aug 8, 2017 by Ajay Kumar

Having looked around a fair bit and changing things around I can't figure out what's wrong with the following and hoping someone looking at this afresh might see it. 

 

Within the Contacts module there is a 'Brands' subpanel (Brand being a custom module). Each brand is related to an Account. What I'm trying to achieve is to have the 'link to existing record' screen for the brand subpanel only show brands that are related to the Account the Contact is currently related to.

 

If I hardcode in the PHP as follows this will work. The user can select the filter and it will filter out those brands that are not related to the account with that ID. I did this to double check my id label was correct.

$viewdefs['BRD_Brand']['base']['filter']['basic']['filters'][] = array(
    'id' => 'filterBrandsTemplate',
    'name' => 'LBL_FILTER_BRANDS_TEMPLATE',
    'filter_definition' => array(
        array(
            'brd_brand_accountsaccounts_ida' => array(
                '$in' => array(
                    '29eac8f4-7930-11e7-96f8-4c327589bfa5'
                ),
            )
        )
    ),
    'editable' => false,
    'is_template' => false
);

 

However when I try to incorporate javascript to make it filter on page load it doesn't work. The below shows the files I've changed. 

 

custom/Extension/modules/BRD_Brand/Ext/clients/base/filters/basic/filterBrandsTemplate.php

<?php
$viewdefs['BRD_Brand']['base']['filter']['basic']['filters'][] = array(
    'id' => 'filterBrandsTemplate',
    'name' => 'LBL_FILTER_BRANDS_TEMPLATE',
    'filter_definition' => array(
        array(
            'brd_brand_accountsaccounts_ida' => array(
                '$in' => array(
                    ''
                ),
            )
        )
    ),
    'editable' => true,
    'is_template' => true
);

 

custom/modules/BRD_Brand/clients/base/fields/link-action/link-action.js 

//overridden the openSelectDrawer() function - only the added custom code is provided in this screenshot
// if we select the brands subpanel within the Contacts module apply the filter options - condition works

if(_.isEqual(this.context.get('parentModel').get('_module'),'Contacts')) {
context.filterOptions = new app.utils.FilterOptions()
.config({
'initial_filter': 'filterBrandsTemplate',
'initial_filter_label': 'LBL_FILTER_BRANDS_TEMPLATE',
'filter_populate': {
'brd_brand_accountsaccounts_ida': [parentModel.get('account_id')] (note: this works and gets the id)
}
})
.format();
}

 

I also added the field into the default.php file incase that was it.

custom/modules/BRD_Brand/clients/base/filters/default/default.php

$module_name = 'BRD_Brand';
$viewdefs[$module_name]['base']['filter']['default'] = array(
    'default_filter' => 'all_records',
    'fields' => array(
        'name' => array(),
        'tag' => array(),
        'assigned_user_name' => array(),
        'brd_brand_accountsaccounts_ida' => array(), (added here)
        '$owner' => array(
            'predefined_filter' => true,
            'vname' => 'LBL_CURRENT_USER_FILTER',
        ),
        '$favorite' => array(
            'predefined_filter' => true,
            'vname' => 'LBL_FAVORITES_FILTER',
        ),
    ),
);

 

I've followed a few others' examples and they don't seem to work for this id field either. I can see the filter on the page being selected on page load however it doesn't actually filter the results out regardless of what I'm trying.

 

Any help as to why the filter isn't working when applied in the JS would be appreciated.

 

Thanks,

Steve

Outcomes