# Search for related field as a filter is not working

**URL:** <https://community.spicecrm.io/t/search-for-related-field-as-a-filter-is-not-working/553>\
**Category:** SpiceUI\
**Created:** [October 19, 2020, 12:56pm UTC](https://community.spicecrm.io/t/search-for-related-field-as-a-filter-is-not-working/553 "2020-10-19T12:56:34Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![vgeorgieva](https://avatars.discourse-cdn.com/v4/letter/v/71e660/32.png) [@vgeorgieva](https://community.spicecrm.io/u/vgeorgieva)\
**Post date:** [October 19, 2020, 12:56pm UTC](https://community.spicecrm.io/t/search-for-related-field-as-a-filter-is-not-working/553/1 "2020-10-19T12:56:34Z")

</div>

Hi,  
I am having issues with the filters in modules. When I create relate field in meetings to contacts, the field works find. But when I try to use it as a filter it doesn’t show any results.  
So I added the field to the fts setup, re-index the records and still no results.  
Can someone help me fixing the field so I can use it as a search field?

---

<div class="post-metadata">

**Author:** ![maretval](https://avatars.discourse-cdn.com/v4/letter/m/b38774/32.png) [@maretval](https://community.spicecrm.io/u/maretval)\
**Post date:** [October 19, 2020, 1:50pm UTC](https://community.spicecrm.io/t/search-for-related-field-as-a-filter-is-not-working/553/2 "2020-10-19T13:50:00Z")

</div>

Could you post your FTS config for meetings?

---

<div class="post-metadata">

**Author:** ![vgeorgieva](https://avatars.discourse-cdn.com/v4/letter/v/71e660/32.png) [@vgeorgieva](https://community.spicecrm.io/u/vgeorgieva)\
**Post date:** [October 19, 2020, 2:06pm UTC](https://community.spicecrm.io/t/search-for-related-field-as-a-filter-is-not-working/553/3 "2020-10-19T14:06:09Z")

</div>

Yes, of course. The name of the field is relate\_contact\_c

 ![image](https://canada1.discourse-cdn.com/flex030/uploads/spicecrm/original/1X/5327ab9774a96193f4a45de77a59cbbc34841f2f.png)

---

<div class="post-metadata">

**Author:** ![maretval](https://avatars.discourse-cdn.com/v4/letter/m/b38774/32.png) [@maretval](https://community.spicecrm.io/u/maretval)\
**Post date:** [October 19, 2020, 2:24pm UTC](https://community.spicecrm.io/t/search-for-related-field-as-a-filter-is-not-working/553/4 "2020-10-19T14:24:47Z")

</div>

When you add field to FTS use tree to get to related module and fields

 ![grafik](https://canada1.discourse-cdn.com/flex030/uploads/spicecrm/original/1X/a4d5d5a66ab7efd73563f7c69caa70a128d42b37.png)

In the end you shall have something similar to this

 ![grafik](https://canada1.discourse-cdn.com/flex030/uploads/spicecrm/original/1X/8581bba50df6db33a405fc60541e573d3eea91bb.png)

Your Link name will be something else. Check in your vardefs

---

<div class="post-metadata">

**Author:** ![vgeorgieva](https://avatars.discourse-cdn.com/v4/letter/v/71e660/32.png) [@vgeorgieva](https://community.spicecrm.io/u/vgeorgieva)\
**Post date:** [October 20, 2020, 6:45am UTC](https://community.spicecrm.io/t/search-for-related-field-as-a-filter-is-not-working/553/5 "2020-10-20T06:45:39Z")

</div>

Yes, I agree with that, but this setup is for relationships such as: 1:1, 1:M, M:M.  
I am trying to use relate field, because it can be found in the filters for the current module.  
Example:

 ![image](https://canada1.discourse-cdn.com/flex030/uploads/spicecrm/original/1X/565271e364e9899057dfa51b66cfe285a0e9419d.png)  
So my issue is to make this field work as a search field.

---

<div class="post-metadata">

**Author:** ![maretval](https://avatars.discourse-cdn.com/v4/letter/m/b38774/32.png) [@maretval](https://community.spicecrm.io/u/maretval)\
**Post date:** [October 20, 2020, 8:06am UTC](https://community.spicecrm.io/t/search-for-related-field-as-a-filter-is-not-working/553/6 "2020-10-20T08:06:43Z")

</div>

How did you define your field?  
Could you post your vardefs?

---

<div class="post-metadata">

**Author:** ![vgeorgieva](https://avatars.discourse-cdn.com/v4/letter/v/71e660/32.png) [@vgeorgieva](https://community.spicecrm.io/u/vgeorgieva)\
**Post date:** [November 19, 2020, 10:10am UTC](https://community.spicecrm.io/t/search-for-related-field-as-a-filter-is-not-working/553/7 "2020-11-19T10:10:26Z")

</div>

Hi, I followed your description for setting up a relationship field in the fts.  
I used standard relationship between accounts and contacts in module Contacts. For the test I added field ‘name’ (from the account) to the contacts’ fts. after re-indexing, re-login I didn’t find field ‘name’ in contacts filters for custom search.

 ![example_1](https://canada1.discourse-cdn.com/flex030/uploads/spicecrm/original/1X/f19ca9286e53d4ec6798df306e610c92027fa132.png)  
 ![example_2](https://canada1.discourse-cdn.com/flex030/uploads/spicecrm/original/1X/e7abc1027e0cae156036ccbd8392e5fd66f7e101.png)

Plus I have this as vardef information:

```
        'accounts' => array(
                'name' => 'accounts',
                'type' => 'link',
                'relationship' => 'accounts_contacts',
                'link_type' => 'one',
                'source' => 'non-db',
                'vname' => 'LBL_ACCOUNT',
                'duplicate_merge' => 'disabled',
                'module' => 'Accounts'
            ),			
        'account_name' => array(
            'name' => 'account_name',
            'rname' => 'name',
            'id_name' => 'account_id',
            'vname' => 'LBL_ACCOUNT_NAME',
            'join_name' => 'accounts',
            'type' => 'relate',
            'link' => 'accounts',
            'table' => 'accounts',
            'isnull' => 'true',
            'module' => 'Accounts',
            'dbType' => 'varchar',
            'len' => '255',
            'source' => 'non-db',
            'unified_search' => true,
        ),
        'account_id' => array(
            'name' => 'account_id',
            'rname' => 'id',
            'id_name' => 'account_id',
            'vname' => 'LBL_ACCOUNT_ID',
            'type' => 'relate',
            'table' => 'accounts',
            'isnull' => 'true',
            'module' => 'Accounts',
            'dbType' => 'id',
            'reportable' => false,
            'source' => 'non-db',
            'massupdate' => false,
            'duplicate_merge' => 'disabled',
            'hideacl' => true,
        ),
```

---

<div class="post-metadata">

**Author:** ![maretval](https://avatars.discourse-cdn.com/v4/letter/m/b38774/32.png) [@maretval](https://community.spicecrm.io/u/maretval)\
**Post date:** [November 20, 2020, 12:41pm UTC](https://community.spicecrm.io/t/search-for-related-field-as-a-filter-is-not-working/553/8 "2020-11-20T12:41:57Z")

</div>

I had a look at the logic for the listview filters: the list does not come from fts configuration.  
It comes from the vardefs.  
Depending on the field type and properties the field is listed or not listed.  
In the case of account\_name, the conditions for listing do not match. That’s why account\_name is not present in the list. account\_name in Contacts is indeed a complex relate field, based on relate field for the id and the search query can’t be built properly in current logic.

Workaround: write the account name as a search term.

---

<div class="post-metadata">

**Author:** ![vgeorgieva](https://avatars.discourse-cdn.com/v4/letter/v/71e660/32.png) [@vgeorgieva](https://community.spicecrm.io/u/vgeorgieva)\
**Post date:** [November 26, 2020, 9:30am UTC](https://community.spicecrm.io/t/search-for-related-field-as-a-filter-is-not-working/553/9 "2020-11-26T09:30:17Z")

</div>

Let me summarize:

- The name, id, and link fields associated with relationships do not appear in the list of filter fields.
- This is not related to any FTS configuration but depends on fields definitions in vardefs.
- It is possible though to use these fields as aggregates in case they are configured through the FTS.

_ **Is the above correct?** _

To cover and close the whole topic I would to touch also filter issues in case a pure relate (not associated with a relationship) is used.

- These relate fields appear in the list of filter fields.
- In the filters you can select such a field to be equal to specific record from the related module (Spice identifies the related module and allows a record to be selected through the related fields).
- The problem is - filter with relate field never returns any results. In case the relate field is not in the FTS configuration - the list view is frozen with grey empty records. In case the relate field is in the FTS configuration the filter returns always 0 records.

_ **What are the options to use pure relate fields in filters in Spice?** _
