Sunday, July 26, 2020

OData Web Services - Filter Option

Hello Friends

NAV/BC OData v4 service can easily accessbile any external system provide the result in json format.

Method for apply different types of filter:

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 “Milano”:
Example: (Access with USER\SERVICE KEY)
Customer > Published Odata Service
https://api.businesscentral.dynamics.com/v2.0/tenant-ID/Production/ODataV4/Company(‘CompanyName’)/Customer?$filter=City%20eq%20%27Milano%27

Available Filters
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).


Filter Expressions
DefinitionExample and explanationC/AL exp.
Select a range of valuesfilter=Entry_No gt 610 and Entry_No lt 615
Query on GLEntry service. Returns entry numbers 611 through 614.
..
Andfilter=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.
&
Orfilter= 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 cannot use OR operators to apply filters on two different fields.
|
Less thanfilter=Entry_No lt 610
Query on GLEntry service. Returns entry numbers that are less than 610.
<
Greater thanfilter= Entry_No gt 610
Query on GLEntry service. Returns entry numbers 611 and higher.
>
Greater than or equal tofilter=Entry_No ge 610
Query on GLEntry service. Returns entry numbers 610 and higher.
>=
Less than or equal tofilter=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.
<>
endswithfilter=endswith(VAT_Bus_Posting_Group,’RT’)
Query on Customer service. Returns all customers with VAT_Bus_Posting_Group values that end in RT.
*
startswithfilter=startswith(Name, ‘S’)
Query on Customer service. Returns all customers names beginning with “S”.
substringoffilter=substringof(Name, ‘urn’)
Query on Customer service. Returns customer records for customers with names containing the string “urn”.
indexoffilter=indexof(Location_Code, ‘BLUE’) eq 0
Query on Customer service. Returns customer records for customers having a location code beginning with the string BLUE.
replacefilter=replace(City, ‘Miami’, ‘Tampa’) eq ‘CODERED’
substringfilter=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.
tolowerfilter=tolower(Location_Code) eq ‘code red’
toupperfilter=toupper(FText) eq ‘2ND ROW’
trimfilter=trim(FCode) eq ‘CODE RED’
concatfilter=concat(concat(FText, ‘, ‘), FCode) eq ‘2nd row, CODE RED’
roundfilter=round(FDecimal) eq 1
floorfilter=floor(FDecimal) eq 0
ceilingfilter=ceiling(FDecimal) eq 1

Referencing Different Data Types in Filter Expressions
You must use the appropriate notation for different data types with filter expressions.
  • String values must be delimited by single quotation marks.
  • Numeric values require no delimiters.
Known Limitations
Filters
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
Lambda operators are not supported by Business Central OData APIs. If lambda operators are used, the filter expression will be ignored.
Deep insert
Business Central supports deep insert, but not deep patching. Multiple requests will need to be issued when patching nested entities.

2 comments:

  1. SMB ERP Solution is a Microsoft Silver Partner. We provide Supply Chain Management Solutions, Microsoft NAV, Microsoft Dynamics NAV, Microsoft Dynamics Business Central. Contact us info@smb-erpsolutions.com for more details. Check out our website for more detials- Dynamics NAV Upgrade

    ReplyDelete
  2. Today I want talk about how to create a new item in business central. It is really a very simple process and you can get new items created very quickly and easily and begin creating sales orders and purchase orders with those new items. check out our website for more details-Creating a new item easily in Business Central

    ReplyDelete