{"title":"Filtering records with the SetRange, SetFilter, GetRangeMin, and GetRangeMax methods","url":"https://jonas-paprotka.de/docs/dev-itpro/developer/devenv-setcurrentkey-setrange-setfilter-getrangemin-and-getrangemax-methods/","by":"JOP-AL","license":"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/devenv-setcurrentkey-setrange-setfilter-getrangemin-and-getrangemax-methods, 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.","credit":"Microsoft Corporation, CC BY 4.0","origin":"https://learn.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/devenv-setcurrentkey-setrange-setfilter-getrangemin-and-getrangemax-methods","source":{"name":"Business Central developer and IT pro docs","repo":"https://github.com/MicrosoftDocs/dynamics365smb-devitpro-pb","commit":"828b6ee72fcd75755627cd6011f3d20899217ab2","date":"2026-11-19"},"checked":"2026-11-19","description":"Describes methods that set limits on the value of one or more specified fields, so that only a subset of the records are displayed, modified, deleted, and so on.","date":"2024-04-18","meta":{"topic":"concept-article"},"outline":[{"level":1,"title":"Filtering records with the SetRange, SetFilter, GetRangeMin, and GetRangeMax methods","slug":"filtering-records-with-the-setrange-setfilter-getrangemin-and-getrangemax-methods","at":0,"chars":2897},{"level":2,"title":"SetRange method","slug":"setrange-method","at":435,"chars":763},{"level":2,"title":"SetFilter method","slug":"setfilter-method","at":1198,"chars":787},{"level":2,"title":"GetRangeMin method","slug":"getrangemin-method","at":1985,"chars":508},{"level":2,"title":"GetRangeMax method","slug":"getrangemax-method","at":2493,"chars":203},{"level":2,"title":"Related information","slug":"related-information","at":2696,"chars":201}],"text":"# Filtering records with the SetRange, SetFilter, GetRangeMin, and GetRangeMax methods\nThe following methods can be used to filter records in a table:\n #setrange-method\n #setfilter-method\n #getrangemin-method\n #getrangemax-method\nThese methods are some of the most commonly used AL methods. They set limits on the value of one or more specified fields, so that only a subset of the records are displayed, modified, deleted, and so on.\n## SetRange method\nSetRange sets a simple filter on a field.\nSetRange has the following syntax.\n```al\nRecord.SetRange(Field [,From-Value] [,To-Value]);\n```\nIn the following example, SetRange filters the Customer table by selecting only those records where the No. field has a value between 10000 and 90000.\n```al\nCustomer.SetRange(\"No.\",'10000','90000');\n```\nWhen you use SetRange the following rules apply:\n SetRange removes any filters that were set previously and replaces them with the From-Value and To-Value parameters that you specify.\n If you use SetRange without setting the From-Value and To-Value parameters, the method removes any filters that are already set.\n If you only set the From-Value, the To-Value is set to the same value as the From-Value.\n## SetFilter method\nSetFilter sets a filter in a more general way than SetRange.\nSetFilter has the following syntax.\n```al\nRecord.SetFilter(Field, String [, Value], ...]);\n```\nField is the name of the field on which you want to set a filter. String is the filter expression. String may contain placeholders, such as %1 and %2, to indicate where to insert the Value parameter\\(s\\) in a filter expression.\nThe following example selects records where the value of No. is larger than 10000 and not equal to 20000.\n```al\nCustomer.SetFilter(\"No.\", '>10000 & <> 20000');\n```\nIf the variables Value1 and Value2 have been assigned \"10000\" and \"20000\" respectively, then you can use the following statement to create the same filter.\n```al\nCustomer.SetFilter(\"No.\",'>%1&<>%2',Value1, Value2);\n```\n## GetRangeMin method\nGetRangeMin retrieves the minimum value of the filter range that is currently applied to a field.\nGetRangeMin has the following syntax.\n```al\nRecord.GetRangeMin(Field);\n```\nA runtime error occurs if the filter that is currently applied is not a range. For example, you can set a filter as follows.\n```al\nCustomer.SetFilter(\"No.\",'10000|20000|30000');\n```\nWith this filter, the following code fails because the filter isn't a range.\n```al\nBottomValue := Customer.GetRangeMin(\"No.\");\n```\n## GetRangeMax method\nGetRangeMax retrieves the maximum value of the filter range that is currently applied to a field.\nGetRangeMax has the following syntax.\n```al\nValue := Record.GetRangeMax(Field)\n```\n## Related information\nmethods-auto/record/record-setrange-method\nmethods-auto/record/record-setfilter-method\nmethods-auto/record/record-getrangemin-method\nmethods-auto/record/record-getrangemax-method"}