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
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
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;
Hope this helps
[View:https://youtu.be/TSQiE42tDwU:320:240]
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.
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.
In such case, you would have to change the approach of including only one field for searching with OR filter expressions.
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
Sohail Ahmed
2,655
Mansi Soni
1,574
YUN ZHU
1,453
Super User 2025 Season 1