Skip to main content

Notifications

Small and medium business | Business Central, N...
Answered

Business Central Odata Endpoint with multiple Contains()

Posted on by 2

Hello Everyone,

I'm currently working on querying the OData v4 /Customer endpoint for Business Central in order to retrieve customers based on a user's search criteria for either name or customer number.

I can successfully make a call to:

https:/api.businesscentral.dynamics.com/v2.0/{_businessCentralOptions.TenantId}/{_businessCentralOptions.Environment}/ODataV4/Company('{_businessCentralOptions.CompanyName}')/Customer


This call retrieves all customers, and I can narrow down the results by adding a filter, for example:

/Customer?$filter=contains(Search_Name,'TESTING')
However, I encountered an issue when attempting to search through both the Search_Name and No fields simultaneously, like this:
 
/Customer?$filter=contains(Search_Name,'TESTING') or contains(No,'50000')
 

This query returns a 501 not implemented error.

In my testing, I found that chaining multiple contains together works if I'm searching within the same field:

/Customer?$filter=contains(Search_Name,'TESTING1') or contains(Search_Name,'TESTING2')
My question is: How can I perform a search on both the Search_Name and No fields simultaneously? I came across an article suggesting the use of the $search option, but it seems to be ignored in my case. Any guidance on this matter would be greatly appreciated.
 
Categories:
  • Verified answer
    YUN ZHU Profile Picture
    YUN ZHU 73,339 Super User 2024 Season 2 on at
    Business Central Odata Endpoint with multiple Contains()
    Hi, as far as I know, the 'OR' operator does not support different fields.
    More details:
    "message": "The 'OR' operator is not supported on distinct fields on an OData filter.  CorrelationId:  6b597f3e-4e78-4442-96e6-1222475cb8ab."
     
    In addition, it may be easy to do in the database, but this is also a very special process in AL Language.
    Dynamics 365 Business Central: Cross-column search (OR filters on multiple fields) ★FilterGroup(-1)
     
    Hope this helps.
    Thanks.
    ZHU

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

New! Quick response templatesâš¡

Save time with the new custom templates!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,228 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,056 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans