Blogger

  • This email address is being protected from spambots. You need JavaScript enabled to view it.

    Recent items

Login

Wednesday, 20 March 2013 10:13

Problem (Resolved) when call ListData.svc and filter by fields with space into its display name

Written by
Rate this item
(0 votes)

In SharePoint 2010, there is a WCF service utilizing ADO.NET Data Service called ListData.svc fulfilling this goal.  You can submit the query by providing the URL containing various commands like sorting, filtering, positioning....etc. 

List all objects of the site
http:/<sp>/_vti_bin/ListData.svc

List all items of the list
http://<sp>/_vti_bin/ListData.svc/ListName

List specific item of the list
http://<sp>/_vti_bin/ListData.svc/ListName(<index>)

List specific item's field value of the list
http://<sp>/_vti_bin/ListData.svc/ListName(<index>)/(<field>)

Filtering
http://<sp>/_vti_bin/ListData.svc/ListName?$filter=<field> <operator> <value>

Lookup field query
http://%3csp%3e/_vti_bin/ListData.svc/ListName?$expand=<LookupList>&$filter=<LookupList>/<LookupField> <operator> <value>

Range (example: getting from 20th to 25th products)
http://<sp>/_vti_bin/Products?$skip20&$top=5


Check MSDN Reference Using Microsoft ADO.NET Data Services for all query options(expand, orderyby, skip, top, filter), operators (eq, ne, gt, ge, lt, le, and, or, not.....), and functions.

In my case, I've used ListData.svc to retrive items from a list. It works fine when I used as filter a field with one word as display name but when I used a field with two or more words as display name I receive this error 400 Bad Request and with Fiddler I inspect the request and view the error:

Show/Hidden xml code

View source
 
 
 
<error xmlns="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata">
    <code/>
    <message xml:lang="it-IT">Syntax error at position 10.</message>
</error>
 
 
 

This is the request: "http://test.virtualsp.com/_vti_bin/ListData.svc/Omologations?$filter=startswith(Model Year,'mo')&$select=Model Year,Id".

Trying to resolve the problem, I've tested:

  • Use the single quote for the display name "http://test.virtualsp.com/_vti_bin/ListData.svc/Omologations?$filter=startswith('Model Year','mo')&$select='Model Year',Id": DOES NOT RESOLVE THE PROBLEM
  • Use the double quote for the display name "http://test.virtualsp.com/_vti_bin/ListData.svc/Omologations?$filter=startswith("Model Year",'mo')&$select="Model Year",Id": DOES NOT RESOLVE THE PROBLEM
  • Use the internal name of the field "http://test.virtualsp.com/_vti_bin/ListData.svc/Omologations?$filter=startswith(OMG_ModelYear,'mo')&$select=OMG_ModelYear,Id": DOES NOT RESOLVE THE PROBLEM
  • Use the display name removing the space from words "http://test.virtualsp.com/_vti_bin/ListData.svc/Omologations?$filter=startswith(ModelYear,'mo')&$select=ModelYear,Id": THIS RESOLVES THE PROBLEM

So, when you want use the ListData.svc and your fields display name has spaces, REMEMBER to remove it into the request and see this beautiful page.

Read 15420 times Last modified on Tuesday, 12 January 2016 10:39

Leave a comment

Make sure you enter all the required information, indicated by an asterisk (*). HTML code is not allowed.