SETRANGE Function (Record)
Sets a simple filter, such as a single range or a single value, on a field.
Record.SETRANGE(Field [,FromValue] [,ToValue])
The record that contains the field that you want to filter.
The field that you want to filter.
The lower limit of the range. The data type of this parameter must match the data type of Field.
The upper limit of the range. If you omit this parameter, then the value that you specified for FromValue is used. The data type of this parameter must match the data type of Field.
SETRANGE is a quick way to set a simple filter on a field.
SETRANGE removes any filters that were set previously and replaces them with the FromValue and ToValue parameters that you specify.
If you use SETRANGE without setting the FromValue and ToValue parameters, then the function removes any filters that are already set.
If you set only the FromValue, then the ToValue is set to the same value as the FromValue.
This example shows how to use the SETRANGE function to specify that you want to see only customers 100 through 200. This example requires that you create the following variable in the C/AL Globals window.
CustomerRec.SETRANGE("No.", '100', '200'); // The above statement is a quick way to set the same filter as: CustomerRec.SETFILTER("No.", '>=100&<=200');
This example shows how to find the first record that has a blank for the requested delivery date. It requires that you create the following variable.
SalesLineRec.SETRANGE("Requested Delivery Date",0D); IF SalesLineRec.FIND('-') THEN MESSAGE('Sales Order %1 has no requested delivery date.', SalesLineRec."Document No.");