How to use OData query option startswith?

1
I’m using OData to expose some entities in the domain model, and I’m struggling with the string functions mentioned in §4.2 of the OData query options. Simple filtering with ‘eq’ works, as does combining predicates with ‘and’ and ‘or’. For example, this URL would give me one SKU record https://www.example.com/odata/Catalog/SKU?$filter=SKUNumber%20eq%20%2787840_100%27 However, when I try to use ‘startswith’, it fails. I’ve noticed the documentation omits the $filter parameter in the examples, but from general OData documentation I know that this should be the query: https://www.example.com/odata/Catalog/SKU?$filter=startswith(SKUNumber,%2787840%27) This gives me an error: <error xmlns="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata"> <code>400</code> <message xml:lang="en-US">Unhandled expression type: CallExp</message> </error> I’ve tried to add spaces (%20) to various places but without success. Using Ronald’s suggestion https://www.example.com/odata/Catalog/SKU?startswith(SKUNumber,%2787840%27) (to be compliant with the documentation) gives another error: <error xmlns="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata"> <code>400</code> <message xml:lang="en-US"> Server cannot process the given uri 'Catalog/SKU' with params 'startswith(SKUNumber,'87840')'. </message> </error>   Does anybody have an idea what is going on here?
asked
2 answers
0

I think you made an error because it should be something like https://www.example.com/odata/Catalog/SKU?startswith(SKUNumber,%2787840%27)

You have to remove the $filter= part.

Regards,

Ronald

[EDIT]

Did you see this stackoverflow about spaces in OData filters? https://stackoverflow.com/questions/19007765/querying-fields-with-name-containing-whitespace-using-odata

answered
0

I’ve contacted Mendix support and the issue has been solved somewhere between versions 7.13.1 and 7.22.2; with the latest Modeler, the query works fine (with the $filter parameter; they’ve told me they would update the documentation accordingly).

answered