{"title":"FieldRef.SetFilter(Text [, Any,...]) Method","url":"https://jonas-paprotka.de/docs/dev-itpro/developer/methods-auto/fieldref/fieldref-setfilter-method/","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/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.","credit":"Microsoft Corporation, CC BY 4.0","origin":"https://learn.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/methods-auto/fieldref/fieldref-setfilter-method","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":"Assigns a filter to a field that you specify.","date":"2026-10-01","meta":{"topic":"reference"},"outline":[{"level":1,"title":"FieldRef.SetFilter(Text [, Any,...]) Method","slug":"fieldrefsetfiltertext-any-method","at":0,"chars":2654},{"level":2,"title":"Syntax","slug":"syntax","at":152,"chars":73},{"level":2,"title":"Parameters","slug":"parameters","at":225,"chars":538},{"level":2,"title":"Remarks","slug":"remarks","at":763,"chars":438},{"level":2,"title":"Example","slug":"example","at":1201,"chars":1317},{"level":2,"title":"Related information","slug":"related-information","at":2518,"chars":136}],"text":"# FieldRef.SetFilter(Text [, Any,...]) Method\n> Version: _Available or changed with runtime version 1.0._\nAssigns a filter to a field that you specify.\n## Syntax\n```al\n FieldRef.SetFilter(String: Text [, Value: Any,...])\n```\n## Parameters\nFieldRef\nType: fieldref-data-type\nAn instance of the fieldref-data-type data type.\nString\nType: ../text/text-data-type\nThe 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.\n*[Optional] Value*\nType: ../any/any-data-type\nReplacement values to insert in replacement fields in the filter expression. The data type of Value must match the type of FieldRef.\n## Remarks\nIf 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.\nOperator|Description\n..|Range\n&|And\n||Or\n\\<|Less than\n\\<=|Less than or equal to\n>|Greater than\n>=|Greater than or equal to\n\\<>|Different from\n*|Forms a part of value\n@|Case-insensitive\nThis method is like the ../record/record-setfilter-method method.\n## Example\nThe 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.\n```al\nvar\n    MyFieldRef: FieldRef;\n    CustomerRecref: RecordRef;\n    Filter1: Text;\n    Filter3: Text;\n    Text000: Label 'Filter before filters set: %1.';\n    Text001: Label 'Filter after filters set: %1.';\nbegin\n    CustomerRecref.Open(Database::Customer);\n    MyFieldRef := CustomerRecref.Field(1);\n    Filter1 := MyFieldRef.GetFilter;\n    Message(Text000, Filter1);\n    MyFieldRef.SetFilter('10000..40000');\n    Filter2 := MyFieldRef.GetFilter;\n    Message(Text001, Filter2);\nend;\n```\n## Related information\nfieldref-data-type\nGet Started with AL<../../devenv-get-started>\nDeveloping Extensions<../../devenv-dev-overview>"}