web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Small and medium business | Business Central, N...
Suggested Answer

Implementing an Items search engine with Business central API

(0) ShareShare
ReportReport
Posted on by 3,013

We are trying to implement a Item search functionality using the Business Central API.

For example, the user may type "PLATE" in the search box, and we want to search by Item No. and Description; so we take this to the API with a request like this:

GET https://

SERVER:7048/BC210/api/v1.0/companies(5b9a4086-229b-ed11-b874-9a7fd23bdbb9)/items?$filter=number eq 'PLATE*' or displayName eq '*PLATE*'

However, this is not a valid request, as the service returns this error:

{
    "error": {
        "code""BadRequest_MethodNotImplemented",
        "message""The 'OR' operator is not supported on distinct fields on an OData filter.  CorrelationId:  00c5784c-da54-4622-b452-a85648391af9."
    }
}

This is quite limiting, as we can't figure out a way to implement a powerful search engine, and in SaaS BC where we don't have a SQL database access.

We would like to avoid the approach of implementing event subscribers in the Item table, and be constantly updating data in a external database that we would use for our search engine, but that's the only path we have come up with so far.

I've noticed that list pages in BC have a search functionality that is able to search in all fields; wondering if there's a way to access this control through API

pastedimage1684314226042v1.png

Another approach could be using multiple API request and combining them, but this could have a poor performance, as on top of multiple request, we would need to filter out duplicates

I have the same question (0)
  • Ghetz Profile Picture
    3,013 on at

    OK! Last call here, in case anyone un the community has an idea.. we really need to implement a item search engine where BC is the datasource

  • Suggested answer
    Manish Kutar Profile Picture
    45 on at

    Hi,

    If you would have gone through the OData filter expressions supported on BC: Using Filter Expressions in OData URIs - Business Central | Microsoft Learn, it clearly mentions that OR filters cannot be used to apply filters on two different fields.

    pastedimage1684486367074v1.png

    In such case, you would have to change the approach of including only one field for searching with OR filter expressions.

  • Ghetz Profile Picture
    3,013 on at

    Honestly Manmeet I dont know What does your answer bring to the table..

    Just asking for ideas about the best way to implement a item search engine where BC is the datasource

    Obviously, one single field search is not enough for our case, so the standard Odata web service is of no help as I posted before.

  • Suggested answer
    Saurav.Dhyani Profile Picture
    14,380 Super User 2025 Season 2 on at

    Hope this helps

    [View:https://youtu.be/TSQiE42tDwU:320:240]

  • Suggested answer
    Haliax Profile Picture
    2 on at
    I came across the same problem, so this might help.
     
    You need to add a flowfilter field in the table, and publish it in the API page, so you can filter it like any other field.
    Then, add something like this in Api page's OnOpenPage trigger:
        trigger OnOpenPage()
        var
            filter_: Text;
        begin
            filter_ := Rec.GetFilter(searchFilter);
            if filter_ <> '' then begin
                Rec.FILTERGROUP := -1;
                Rec.SetFilter("Description", filter_);
                Rec.SetFilter("Search Description", filter_);
            end;
        end;
    Adding "FILTERGROUP := -1" enables cross-column search. Remember to get and save the filter value before setting FILTERGROUP, or it will be empty
     
    /items?$filter=searchFilter eq 'chair'
     
     

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Small and medium business | Business Central, NAV, RMS

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 3,064

#2
Jainam M. Kothari Profile Picture

Jainam M. Kothari 1,568 Super User 2025 Season 2

#3
YUN ZHU Profile Picture

YUN ZHU 1,063 Super User 2025 Season 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans