# loadRecords vs addFoundSetFilterParam

**URL:** <https://forum.servoy.com/t/loadrecords-vs-addfoundsetfilterparam/10248>\
**Category:** Classic Servoy\
**Created:** [February 10, 2009, 5:21am UTC](https://forum.servoy.com/t/loadrecords-vs-addfoundsetfilterparam/10248 "2009-02-10T05:21:04Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![4xjbh](https://avatars.discourse-cdn.com/v4/letter/4/ea666f/32.png) [@4xjbh](https://forum.servoy.com/u/4xjbh)\
**Post date:** [February 10, 2009, 5:21am UTC](https://forum.servoy.com/t/loadrecords-vs-addfoundsetfilterparam/10248/1 "2009-02-10T05:21:04Z")

</div>

I recently was trying to filter a contacts table (containing employees & contacts) and the 2 methods I came up with were the following:

```auto
foundset.loadRecords('SELECT contact.contact_id FROM contact WHERE type_id = 2'); 

```

and

```auto
foundset.addFoundSetFilterParam('type_id','=','2');
foundset.loadAllRecords();

```

On the surface they both seem to work and I was wondering if there was a right and wrong use. I also found **addTableFilterParam** worked also.

---

<div class="post-metadata">

**Author:** ![ngervasi](https://avatars.discourse-cdn.com/v4/letter/n/f9ae1b/32.png) [@ngervasi](https://forum.servoy.com/u/ngervasi)\
**Post date:** [February 10, 2009, 11:37am UTC](https://forum.servoy.com/t/loadrecords-vs-addfoundsetfilterparam/10248/2 "2009-02-10T11:37:41Z")

</div>

All of the above work fine but it depends on what you want to achieve.  
If you need to set a permanent filter use addTableFilterParam, once the filter is in place it will be used everywhere (it will be appended to ANY query sent to the DB), every foundset created after the filter setup will be filtered.  
If you need to apply a filter but just for the current foundset use addFoundSetFilterParam, any future search on that foundset will go trough the filter.  
If you use loadRecords(query,args) keep in mind that any future search on that foundset will not honor the intial where condition (ex: if the user, after the intial load, searches all contacts starting with “A” he will also find contacts with type\_id != 2).

As a side note: if you use loadRecords use the following syntax to take advantage of the prepared statements (faster and easier to read):

```auto
foundset.loadRecords('SELECT contact.contact_id FROM contact WHERE type_id = ?',[2]);

```

---

<div class="post-metadata">

**Author:** ![4xjbh](https://avatars.discourse-cdn.com/v4/letter/4/ea666f/32.png) [@4xjbh](https://forum.servoy.com/u/4xjbh)\
**Post date:** [February 11, 2009, 11:28pm UTC](https://forum.servoy.com/t/loadrecords-vs-addfoundsetfilterparam/10248/3 "2009-02-11T23:28:24Z")

</div>

I found **addFoundSetFilterParam** does not work with a related foundset. If I want to filter the related foundet by “type\_id” what function do I use?

Example: Table of communications and I want to have a tab that only shows notes for the related contact.

---

<div class="post-metadata">

**Author:** ![Joas](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/joas/32/5095_2.png) [@Joas](https://forum.servoy.com/u/Joas)\
**Post date:** [February 12, 2009, 7:38am UTC](https://forum.servoy.com/t/loadrecords-vs-addfoundsetfilterparam/10248/4 "2009-02-12T07:38:36Z")

</div>

For that you have to create a relation from communication.contact\_id to notes.contact\_id and use that relation to add the tab.

---

<div class="post-metadata">

**Author:** ![4xjbh](https://avatars.discourse-cdn.com/v4/letter/4/ea666f/32.png) [@4xjbh](https://forum.servoy.com/u/4xjbh)\
**Post date:** [February 12, 2009, 11:29am UTC](https://forum.servoy.com/t/loadrecords-vs-addfoundsetfilterparam/10248/5 "2009-02-12T11:29:35Z")

</div>

edited: I have done this (refer attachment) it seems to work. Any problems with doing it this way?

---

<div class="post-metadata">

**Author:** ![ROCLASI](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/roclasi/32/4371_2.png) [@ROCLASI](https://forum.servoy.com/u/ROCLASI)\
**Post date:** [February 12, 2009, 11:36am UTC](https://forum.servoy.com/t/loadrecords-vs-addfoundsetfilterparam/10248/6 "2009-02-12T11:36:23Z")

</div>

Hi James,

You can use an extra (global) field in the join that links to the type. Just by setting the global you will filter the relationship instantly.

Hope this helps.

---

<div class="post-metadata">

**Author:** ![ROCLASI](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/roclasi/32/4371_2.png) [@ROCLASI](https://forum.servoy.com/u/ROCLASI)\
**Post date:** [February 12, 2009, 12:08pm UTC](https://forum.servoy.com/t/loadrecords-vs-addfoundsetfilterparam/10248/7 "2009-02-12T12:08:24Z")

</div>

Hi James,

That should work.
