AnsweredAssumed Answered

Filter by ID

Question asked by Francesca Shiekh on Jun 15, 2015
Latest reply on Feb 11, 2016 by varun_gupta34
I have a custom filter that I would expect to be able to use with an array of ids to open a selection-list drawer with only the accounts in the array.

  $viewdefs['Accounts']['base']['filter']['basic']['filters'][] = array(
  'id' => 'FilterAccountsIdTemplate',
  'filter_definition' => array(
      'id' => array(
  'editable' => true,
  'is_template' => true,

The ids are returned by an API call which gets the Account IDs related to a Contact (we have am M-N relationship between Accounts and Contacts).
The intent is, if there is only one account related to the contact, populate the Account relate field on this module, else, present the user with a selection-list drawer with only Accounts related to the selected Contact

({  extendsFrom: 'CreateActionsView',
  initialize: function(options){
    this._super('initialize', [options]);
    this.model.on('change:case_primary_contact_c', this.updateAccount, this);
  updateAccount: function() {   
      var contact_id = this.model.get('contact_id_c'),
          url = app.api.buildURL('Contacts/'+contact_id+'/link/accounts_contacts/');'GET', url, null, {
        success: _.bind( function (data){
          if(data.records.length == 1){
            this.model.set('account_id', data.records[0].id);
            this.model.set('account_name', data.records[0].name);
          }else if(data.records.length >1){
           console.log('more than 1');
            var account_ids = [];
            _.each(data.records, function (record){
              account_ids.push(; //generate array of Account ids
            var filterOptions = new app.utils.FilterOptions()
                'initial_filter': 'FilterAccountsByIdTemplate',
                'initial_filter_label': 'LBL_FILTER_ACCOUNTS_BY_ID_TEMPLATE',
                'filter_populate': {
              layout: 'selection-list',
              context: {
                module: 'Accounts',
                filterOptions: filterOptions,
        }, this),
          console.log("Error retrieving Account related to Contact" + o);
        }, this),

But, although the filter shows in the selection-list, the criteria is not applied (it shows all accounts as if unfiltered)

I suspect the problem is filtering by ID, which is not normally a filter field.

Any suggestions on how to get around this?