# FieldRef.SetFilter(Text [, Any,...]) Method
> Version: _Available or changed with runtime version 1.0._
Assigns a filter to a field that you specify.
## Syntax
```al
 FieldRef.SetFilter(String: Text [, Value: Any,...])
```
## Parameters
FieldRef
Type: fieldref-data-type
An instance of the fieldref-data-type data type.
String
Type: ../text/text-data-type
The filter expression. A valid expression consists of alphanumeric characters and one or more of the following operators: \<, \>, , &, |, and =. You can use replacement fields (%1, %2, and so on) to insert values at run time.
*[Optional] Value*
Type: ../any/any-data-type
Replacement values to insert in replacement fields in the filter expression. The data type of Value must match the type of FieldRef.
## Remarks
If the method is called with a field for which a filter already exists, the filter is removed before a new one is set. You can construct filters using the following operators.
Operator|Description
..|Range
&|And
||Or
\<|Less than
\<=|Less than or equal to
>|Greater than
>=|Greater than or equal to
\<>|Different from
*|Forms a part of value
@|Case-insensitive
This method is like the ../record/record-setfilter-method method.
## Example
The following example opens the Customer table as a RecordRef variable that is named CustomerRecref. The ../recordref/recordref-field-method creates a FieldRef for the first field \(No.\) and stores the reference in the MyFieldRef variable. The fieldref-getfilter-method retrieves the filters that are set on the No. field and stores the value in the Filter1 variable. The value of any filter that is set is displayed in a message box. The SetFilter method sets a filter that selects records from 10000 to 40000 in the No. field. The fieldref-getfilter-method retrieves and stores the new filter in the Filter2 variable and displays it in a message. The value in the Filter1 variable is blank because no filter is set. The value in Filter2 is 10000..40000 because of the filter that is set by the SetFilter method.
```al
var
    MyFieldRef: FieldRef;
    CustomerRecref: RecordRef;
    Filter1: Text;
    Filter3: Text;
    Text000: Label 'Filter before filters set: %1.';
    Text001: Label 'Filter after filters set: %1.';
begin
    CustomerRecref.Open(Database::Customer);
    MyFieldRef := CustomerRecref.Field(1);
    Filter1 := MyFieldRef.GetFilter;
    Message(Text000, Filter1);
    MyFieldRef.SetFilter('10000..40000');
    Filter2 := MyFieldRef.GetFilter;
    Message(Text001, Filter2);
end;
```
## Related information
fieldref-data-type
Get Started with AL<../../devenv-get-started>
Developing Extensions<../../devenv-dev-overview>

Copyright (c) Microsoft Corporation. CC BY 4.0, https://creativecommons.org/licenses/by/4.0/; code samples MIT. From https://learn.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/methods-auto/fieldref/fieldref-setfilter-method, MicrosoftDocs/dynamics365smb-devitpro-pb at 828b6ee (2026-11-19). Changed: includes filled in, links to this site, and for agents shortened without dropping a fact. https://jonas-paprotka.de/docs/dev-itpro/developer/methods-auto/fieldref/fieldref-setfilter-method/
