Assigns a filter to a field that you specify.
FieldRef.SETFILTER(String [, Value],...)
- Type: FieldRef The FieldRef that refers to the field that you want to place a filter on.
- Type: Text or Code 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.
- Type: any Replacement values to insert in replacement fields in the filter expression. The data type of Value must match the type of FieldRef.
If the function 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.
Less than or equal to
Greater than or equal to
Forms a part of value
This function is like the SETFILTER Function (Record) function.
The following example opens the Customer table as a RecordRef variable that is named CustomerRecref. The FIELD Function (RecordRef) creates a FieldRef for the first field (No.) and stores the reference in the MyFieldRef variable. The GETFILTER Function (FieldRef) 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 function sets a filter that selects records from 10000 to 40000 in the No. field. The GETFILTER Function (FieldRef) 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 function. This example requires that you create the following variables and text constants in the C/AL Globals windows.
|Text constant||ENU value|
Filter before filters set: %1.
Filter after filters set: %1.
CustomerRecref.OPEN(DATABASE::Customer); MyFieldRef := CustomerRecref.FIELD(1); Filter1 := MyFieldRef.GETFILTER; MESSAGE(Text000, Filter1); MyFieldRef.SETFILTER('10000..40000'); Filter2 := MyFieldRef.GETFILTER; MESSAGE(Text001, Filter2);