The AL developer preview is still evolving with frequent updates. Follow us on the Dynamics NAV Team Blog for the announcements.
GETFILTERS Method (Query)
Returns the filters that are applied to all columns in the query.
The following code shows the syntax of the GETFILTERS method.
Query is a variable of the Query data type that specifies the query object.
Filter := Query.GETFILTERS
A text string that lists the filters that are set on all columns of the query. If there are no applicable filters, then an empty string is returned.
The GETFILTERS method returns the filters that are currently set for all data columns and filter rows by the SETFILTER Method (Query) method, SETRANGE Method (Query) method, and the ColumnFilter Property in Query Designer. The GETFILTER method does not return filters that are set on a column's source field by the DataItemTableFilter Property in Query Designer or global filters that are set by the FILTERGROUP method.
A filter row is row in Query Designer that is used to filter on a field that is not included in the resulting dataset.
You can call the GETFILTERS method multiple times and at any point in the code. If you call the GETFILTERS method before the first SETFILTER or SETRANGE method call, then the GETFILTERS method returns only filters that are set by the ColumnFilter property of the columns.
Filters that are set by the SETFILTER method and SETRANGE method are applied to a query when the query is opened by using a call to the OPEN, the SAVEASXML, or SAVEASCSV methods. You must consider the location of the GETFILTERS method with respect to these methods to obtain the results that you want. For example, in the following two code examples, the GETFILTERS method will return the filter set by the SETFILTER method call. However, in the first example, the filter has been applied to the query dataset; in the second example, the filter has not been applied.
Query.SETFILTER(Column, String); Query.OPEN; Query.GETFILTERS; Query.READ;
Query.OPEN; Query.SETFILTER(Column, String); Query.GETFILTERS; Query.READ;
The following AL code example demonstrates how to use the GETFILTERS method on a query. The example code sets filters on a query column, and then displays a message when the query is run that indicates the filter on the column.
This example requires that you do the following:
Create a query called Customer_SalesQuantity that has the following characteristics:
Links table 18 Customer with table 37 Sales Lines from the CRONUS International Ltd. demonstration database.
Includes columns for the Name and No. fields from the Customer table and the Quantity field from Sales Lines table.
The ColumnFilter property of the Quantity column is set with a filter that includes values greater than 10.
Create the following AL variables and text constant in the object that will run the query.
Variable name DataType Subtype MyQuery Query Customer_SalesQuantity MyFilters Text Not applicable Text constant name ENU Value Text000 The filters are as follows: %1
The following AL code runs the query and displays a message that contains the filter that is set on a query column. You can add the code to the OnRun trigger of a codeunit, and then run the codeunit to see the results.
// Sets a filter to display only sales quantities greater than 10. This overwrites the value of ColumnFilter property. MyQuery.SETFILTER(Quantity, '>10'); // Sets a filter to display the columns with the value Selangorian Ltd. only. MyQuery.SETFILTER(NAME, 'Selangorian Ltd.'); // Runs the query and applies the filter. MyQuery.OPEN; // Returns the filters that are on the Quantity column and displays the filters in a message. MyFilters := MyQuery.GETFILTERS; MESSAGE(Text000, MyFilters);
Running the code returns the following message:
The filters are as follows: Quantity > 10, Name = Selangorian Ltd.