# Limit the NG Filter + Free Search?

**URL:** <https://forum.servoy.com/t/limit-the-ng-filter-free-search/20588>\
**Category:** Questions\
**Created:** [October 1, 2021, 12:04am UTC](https://forum.servoy.com/t/limit-the-ng-filter-free-search/20588 "2021-10-01T00:04:30Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![john1598360627](https://avatars.discourse-cdn.com/v4/letter/j/439d5e/32.png) [@john1598360627](https://forum.servoy.com/u/john1598360627)\
**Post date:** [October 1, 2021, 12:04am UTC](https://forum.servoy.com/t/limit-the-ng-filter-free-search/20588/1 "2021-10-01T00:04:30Z")

</div>

> **[Home](https://github.com/Servoy/svyPopupFilter/wiki)**
>
> Contribute to Servoy/svyPopupFilter development by creating an account on GitHub.

I’m curious how to do something with the PopupFilter, and the Free Search.

I want to limit the Filter & Search by a hidden pre-filter.

Example; Grid should show the records for a specific Period value. I want the Free Search results apply that Period filter always.

Right now I’m just using a query to limit the foundset initially, but I want to do it for the search results too.

I know this is possible somehow but I’m not sure which way to do so. onSearchCommand? onFilterApplyEvent? onFilterApplyQueryCondition? Auto Apply? Sorry I’m just confused which one is used for the case I’m talking about.

---

<div class="post-metadata">

**Author:** ![paronne](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/paronne/32/5096_2.png) [@paronne](https://forum.servoy.com/u/paronne)\
**Post date:** [October 1, 2021, 6:57am UTC](https://forum.servoy.com/t/limit-the-ng-filter-free-search/20588/2 "2021-10-01T06:57:51Z")

</div>

Hi John,

what you describe is possible indeed.  
Using the onSearchCommand you can amend the generated Query adding extra conditions and load it into the foundset.  
As in wiki [https://github.com/Servoy/svyPopupFilte … tom-search](https://github.com/Servoy/svyPopupFilter/wiki#custom-search)

```auto
	// set the onSearchCommand
	toolbarFilter.setOnSearchCommand(onSearchCommand)

function onSearchCommand(query, fs) {
	// add custom conditions to the query
	query.where.add(query.columns.orderdate.not.isNull);

	// apply the query to the foundset
	fs.loadRecords(query);
}

```

Regards,  
Paolo

---

<div class="post-metadata">

**Author:** ![john1598360627](https://avatars.discourse-cdn.com/v4/letter/j/439d5e/32.png) [@john1598360627](https://forum.servoy.com/u/john1598360627)\
**Post date:** [October 1, 2021, 10:20pm UTC](https://forum.servoy.com/t/limit-the-ng-filter-free-search/20588/3 "2021-10-01T22:20:31Z")

</div>

> paronne:  
> Hi John,
> 
> what you describe is possible indeed.  
> Using the onSearchCommand you can amend the generated Query adding extra conditions and load it into the foundset.  
> As in wiki [https://github.com/Servoy/svyPopupFilte … tom-search](https://github.com/Servoy/svyPopupFilter/wiki#custom-search)
> 
> ```auto
> // set the onSearchCommand
> 
> ```

```
toolbarFilter.setOnSearchCommand(onSearchCommand)

```

function onSearchCommand(query, fs) {  
// add custom conditions to the query  
query.where.add(query.columns.orderdate.not.isNull);

```
// apply the query to the foundset
fs.loadRecords(query);

```

}

> ```auto
> 
> Regards,
> Paolo
> 
> ```

Thank you!
