When working with filters and record ranges in AL , two handy functions often come into play: GETRANGEMIN()
and GETRANGEMAX()
. These functions help you programmatically access the lower and upper bounds of a filter applied to a field in a record. This can be especially useful for creating reports, processing data, or passing filters between records.
These two functions are part of the Record data type and help retrieve the range boundaries for a specific field filter.
GETRANGEMIN(Field)
: Returns the lowest value in the filter range for the specified field.GETRANGEMAX(Field)
: Returns the highest value in the filter range for the specified field.If there is no filter set for the field, both functions return blank.
SalesHeader.SETFILTER("No.", '1000..2000');
MinNo := SalesHeader.GETRANGEMIN("No."); // Returns '1000'
MaxNo := SalesHeader.GETRANGEMAX("No."); // Returns '2000'
Use Cases
1. Transferring Filter Ranges
If you’re applying a filter on one table and want to use the same range on another:
Customer.SETFILTER("No.", 'C00010..C00020');
SalesHeader.SETRANGE("Sell-to Customer No.", Customer.GETRANGEMIN("No."), Customer.GETRANGEMAX("No."));
2. Generating Custom Reports
SalesHeader.SETFILTER("Posting Date", '2024-01-01..2024-01-31');
StartDate := SalesHeader.GETRANGEMIN("Posting Date");
EndDate := SalesHeader.GETRANGEMAX("Posting Date");
MESSAGE('Report for: %1 to %2', StartDate, EndDate);
3. Validating Filtered Data
IF (SalesHeader.GETRANGEMIN("Posting Date") < AllowedStartDate) OR
(SalesHeader.GETRANGEMAX("Posting Date") > AllowedEndDate) THEN
ERROR('Filter range is outside allowed period.');
The GETRANGEMIN()
and GETRANGEMAX()
functions are powerful tools when working with dynamic filters in AL. They enable developers to write cleaner, more adaptable code by directly accessing the boundaries of filter conditions.
Stay Tuned for more updates.
Original Post https://ammolhsaallvi.blog/2025/04/30/understanding-getrangemin-and-getrangemax-in-business-central/