Dynamically filter Reseller Contacts by Reseller Account in Accounts module?

I’m running into issues trying to get a filter to work for a couple of Relate fields. I'm pretty new at this so hopefully it's something really basic that I've missed.

I have added two new Relate type fields (Reseller Account and Reseller Contact) on the Accounts module so that I can show the Reseller account and the Reseller contact that the Account does business with:

The Reseller Contact should be filtered by the Reseller Account so when the “Search and Select” is run, it should pre-filter the list of contacts for the selected Reseller Account.

The problem is that when I click on the “Search and Select” to search for the Reseller Contact, it shows the selected Reseller Account as the filter parameter, but it says that there is no data available:

It I manually type in that same Reseller account name and re- run the search, the list on contacts are correctly filtered:

 

I built the logic based on several examples, including:  https://sugarclub.sugarcrm.com/dev-club/f/questions-answers/1319/dynamically-filter-contacts-by-account-in-quotes-module , so I’m wondering what I may have missed?

 

Here’s my code:

Two new fields:

reseller_c (Relate field, Accounts module)

resellercnt_c (Relate field, Contacts module).

 

Code:

custom/Extension/modules/Contacts/Ext/clients/base/filters/basic/filterResellerContacTemplate.php

<?php

$viewdefs['Contacts']['base']['filter']['basic']['filters'][] = array(

    'id' => 'filterContactsByAccountId',

    'name' => 'LBL_ACCOUNT_ID_FOR_CONTACT',

    'filter_definition' => array(

        array(

            'account_id' => ''  

        ),

    ),

    'editable' => true,

    'is_template' => true,

);

 

custom/modules/Accounts/clients/base/views/record/record.php

           10 =>

              array (

                'readonly' => false,

                'name' => 'resellercnt_c',

                'studio' => 'visible',

                'label' => 'LBL_RESELLERCNT',

                'initial_filter' => 'filterContactsByAccountId',

                'initial_filter_label' => 'LBL_ACCOUNT_ID_FORCONTACT',

                'filter_relate'=>array(

                   'reseller_c'=>'account_id'

                )

              ),

 

custom/modules/Accounts/clients/base/fields/relate/relate.js

({

    extendsFrom: 'RelateField',

    initialize: function (options) {

        this._super('initialize', [options]);

    },

    //Filter contacts to the Reseller Company's list of contacts

    getFilterOptions: function (force) {

        if (this._filterOptions && !force) {

            return this._filterOptions;

        }

        if (this.getSearchModule() == 'Contacts' && this.def.name=='resellercnt_c') {

            this._filterOptions = new app.utils.FilterOptions()

                .config({

                    'initial_filter': 'filterContactsByAccountId',

                    'initial_filter_label': 'LBL_ACCOUNT_ID_FORCONTACT',

                    'filter_populate': {

                        'account_id': this.model.get('reseller_c'),

                    },

                    'filter_relate': {

                        'account_id': this.model.get('reseller_c'),

                    }

                })

                .populateRelate(this.model)

                .format();

        } else {

            this._filterOptions = new app.utils.FilterOptions()

                .config(this.def)

                .setInitialFilter(this.def.initial_filter || '$relate')

                .populateRelate(this.model)

                .format();

        }

        return this._filterOptions;

    },

})

 

custom/Extension/modules/Contacts/Ext/Language/en_us.filterContactResellerLabel.php

<?php

 $mod_strings['LBL_ACCOUNT_ID_FORCONTACT'] = 'Contacts for Reseller';

?>

 

custom/Extension/modules/Accounts/Ext/Vardefs

<?php

 // created: 2022-06-15 23:05:12

$dictionary['Account']['fields']['resellercnt_c']['labelValue']='Reseller Contact';

$dictionary['Account']['fields']['resellercnt_c']['dependency']='isInList($account_type,createList("Customer","Partner","Investor","Analyst","Competitor","Integrator","Other","Prospect","Press"))';

$dictionary['Account']['fields']['resellercnt_c']['required_formula']='';

$dictionary['Account']['fields']['resellercnt_c']['readonly_formula']='';

$dictionary['Account']['fields']['resellercnt_c']['filter_definition'] = [

    [

        'account_id' => '#reseller_c'

    ]

];

 ?>