Editar

Partilhar via


Using filter expressions in OData URIs

You use filter expressions in OData URIs to limit the results in a returned document. This article lists the filter expressions, and describes the equivalent field or table filter in AL. It provides examples of syntax for using filter expressions in OData URIs and applications.

Filter expressions

To add a filter to an OData URI, add $filter= to the end of the name of the published web service. For example, the following URI filters the City field in the Customer page to return all customers who are located in Miami:

https://localhost:7048/BC240/ODataV4/Company('CRONUS International Ltd.')/Customer?$filter=City eq 'Miami'  

The following table shows the filters that are supported in Business Central OData web services and their equivalent AL filter expressions. All examples are based either on page 21, Customer (published as Customer), or on page 20, General Ledger Entry (published as GLEntry).

Definition Example and explanation Equivalent AL expression
Select a range of values $filter=Entry_No gt 610 and Entry_No lt 615

Query on GLEntry service. Returns entry numbers 611 through 614.
..
In a list of values $filter=EntryNo in (610, 612, 614)

Query that returns entry numbers 610, 612, and 614

Note: This only works in $schemaversion=2.1.
And $filter=Country_Region_Code eq 'ES' and Payment_Terms_Code eq '14 DAYS'

Query on Customer service. Returns customers in Spain where Payment_Terms_Code=14 DAYS.
&
Or $filter= Country_Region_Code eq 'ES' or Country_Region_Code eq 'US'

Query on Customer service. Returns customers in Spain and the United States.

Alert: You can use OR operators to apply different filters on the same field. However, you can't use OR operators to apply filters on two different fields.
|
Less than $filter=Entry_No lt 610

Query on GLEntry service. Returns entry numbers that are less than 610.
<
Greater than $filter= Entry_No gt 610

Query on GLEntry service. Returns entry numbers 611 and higher.
>
Greater than or equal to $filter=Entry_No ge 610

Query on GLEntry service. Returns entry numbers 610 and higher.
>=
Less than or equal to $filter=Entry_No le 610

Query on GLEntry service. Returns entry numbers up to and including 610.
<=
Different from (not equal) $filter=VAT_Bus_Posting_Group ne 'EXPORT'

Query on Customer service. Returns all customers with VAT_Bus_Posting_Group not equal to EXPORT.
<>
endswith $filter=endswith(VAT_Bus_Posting_Group,'RT')

Query on Customer service. Returns all customers with VAT_Bus_Posting_Group values that end in 'RT'.
*
startswith $filter=startswith(Name, 'S')

Query on Customer service. Returns all customers names beginning with 'S'.
*
contains $filter=contains(Name, 'urn')

Query on Customer service. Returns customer records for customers with names containing the string “urn”.
substring $filter=substring(Location_Code, 5) eq 'RED'

Query on Customer service. Returns true for customers with the string RED in their location code starting as position 5.
tolower $filter=tolower(Location_Code) eq 'code red'
toupper $filter=toupper(FText) eq '2ND ROW'

Note

These filters are more robust and more flexible in $schemaversion=2.1.

Note

There is a special filter, journals.templateDisplayName which returns default journals if a user hasn't defined the filter criteria.

Note

You can learn more about setting the filters that are specific to AL language by checking out Enter criteria in Filters article.

Filters without equivalent AL expressions

For filters that don't have equivalent AL expressions, the platform uses the closest available AL approximation. For example, tolower and toupper disable case sensitivity in comparisons, and substring gets turned into * wild card operators.

If there's no AL approximation, an error is reported. For example, an error can occur if you perform Or over different fields, like field1 eq 1 or field2 eq 2.

Referencing different data types in Filter expressions

Use the appropriate notation for different data types with filter expressions.

  • Delimit string values by single quotation marks.

  • Numeric values require no delimiters.

Nested function calls

Nested function calls in filter clauses are supported in $schemaversion=2.1 and later. Nested function calls aren't supported in earlier schema versions, which means that filter clause expressions like contains(tolower(field), 'some') don't return the expected results. In this case, a partial case-insensitive text search - but instead either throws an error or returns an undefined result.

OData Web Services
Microsoft OData Docs - Query options overview