0

I have a Posts list(Blog) I would like to use the rest api call below to filter the list using a lookup value Category When i test it using the Byline field below it works

http://Site/news/_vti_bin/listdata.svc/Posts?$filter=year(Published) eq 2019 and month(Published) eq 10 and Byline eq 'Test'

But when i do something like this below

http://Site/news/_vti_bin/listdata.svc/Posts?$select=Title,Category/Title,Category/Id&$expand=Category/Id&$filter=year(Published) eq 2019 and month(Published) eq 7 and Category/Title eq 'Events'&$expand=Category

I get the error:

No property 'Title' exists in type 'System.Collections.Generic.IEnumerable`1[[Microsoft.SharePoint.Linq.DataServiceEntity, Microsoft.SharePoint.Linq, Version=16.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c]]' at position 63.
2
  • Are you able to change the endpoint? Listdata.svc is deprecated. I recommend you to use the Rest API which is more reliable in long term and allow you to expand lookup field with less troubles. – Vladimir Herrlein Nov 6 '19 at 8:48
  • yes i can but the issue is i have is i need to extract month and year from the published date like so year(Published) for my filtering but this only works when i use listdata.svc. – naijacoder Nov 6 '19 at 22:32
0

Suggest you use REST API to achieve instead of listdata.svc.

And Category column's internal name is "PostCategory", not "Category".

A demo for your reference:

https://<site url>/_api/web/lists/GetByTitle('Posts')/items?$select=Title,PostCategory/Title&$filter=PostCategory/Title eq 'Events'&$expand=PostCategory
1
  • Thanks Kally. I know i can do this with rest api but the issue is i have is i need to extract month and year from the published date like so year(Published) but this only works when i use listdata.svc. – naijacoder Nov 6 '19 at 22:31
0

So your main trouble is the way to filter date time by year and month through the REST API. As the listdata.svc is deprecated since a while. I couldn’t recommend to continue your research in that way.

One solution would be filtering the datetime field Published such as the following.

/_api/web/lists/list_entity_name/items?$select=Title,Category/Title&$expand=Category/Title&$filter=Published ge datetime’2019-07-01T00:00:00Z’ and Published lt datetime’2019-08-01T00:00:00Z’

Or if you can make an HTTP Post request, using the REST API method GetItems by passing a CAML query in the body. But you will not be able to expand the lookup field, to retrieve the value you will have to change or add an extension of your Category field to retrieve the value from the ViewField.

Request

POST /_api/web/lists/list_entity_name/GetItems

Data

{ “query” : { “ViewXml” : “Your CAML query” } }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.