OData Web Services – About Using Filter Expressions
I want to report some information on the use and properties of OData with Business Central, very useful and I would say indispensable if we use the Business Central Cloud environment.
The Open Data Protocol (OData) is a web protocol that is designed for querying tabular data and provides you with an alternative to SOAP-based web services.
OData uses URIs for resource identification and commits to an HTTP-based, uniform interface for interacting with resources.
You can use OData web services to show Business Central data, and you can update data in a Business Central database using OData web services.
OData – Filter Expressions
Using Filter Expressions in OData URIs
You can use filter expressions in OData URIs to limit the results that are returned in an AtomPub document. This topic identifies the filter expressions that you can use, describes the equivalent field or table filter that you can use in C/AL, and presents examples to show the syntax for using filter expressions in OData web service URIs and applications.
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 “Milano”:
Example: (Access with USER\SERVICE KEY)
Customer > Published Odata Service
The following table shows the filters that are supported in Business Central OData web services and the equivalent C/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).
Query on GLEntry service. Returns entry numbers 611 through 614.
Query on Customer service. Returns customers in Spain where Payment_Terms_Code=14 DAYS.
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 cannot use OR operators to apply filters on two different fields.
Query on GLEntry service. Returns entry numbers that are less than 610.
Query on GLEntry service. Returns entry numbers 611 and higher.
Query on GLEntry service. Returns entry numbers 610 and higher.
Query on GLEntry service. Returns entry numbers up to and including 610.
Query on Customer service. Returns all customers with VAT_Bus_Posting_Group not equal to EXPORT.
Query on Customer service. Returns all customers with VAT_Bus_Posting_Group values that end in RT.
Query on Customer service. Returns all customers names beginning with “S”.
Query on Customer service. Returns customer records for customers with names containing the string “urn”.
Query on Customer service. Returns customer records for customers having a location code beginning with the string BLUE.
Query on Customer service. Returns true for customers with the string RED in their location code starting as position 5.
Referencing Different Data Types in Filter Expressions
You must use the appropriate notation for different data types with filter expressions.
You can specify filters in OData web services in general that are not supported in Business Central , such as using an OR operator to filter on “two different fields.
In those cases, you will see the following error:
“An error occurred while processing this request. The ‘OR’ operator is not supported on distinct fields on an OData filter”
Lambda operators are not supported by Business Central OData APIs. If lambda operators are used, the filter expression will be ignored.
Business Central supports deep insert, but not deep patching. Multiple requests will need to be issued when patching nested entities.
L'articolo OData Web Services – About Using Filter Expressions proviene da Roberto Stefanetti Blog - Microsoft Dynamics 365 Business Central.