1

When filtering a text column like in built Title field using startswith, proper results are returned. Example:

http://aissp2013:111/_vti_bin/ListData.svc/ChangeRules()?$filter=startswith(Title,'Ti')

However, startswith does not seem to work with inbuilt Id field. Following REST queries do not work:

http://aissp2013:111/_vti_bin/ListData.svc/ChangeRules()?$filter=startswith(Id,1)
http://aissp2013:111/_vti_bin/ListData.svc/ChangeRules()?$filter=startswith(Id,'1')

But querying the Id field using eq works:

http://aissp2013:111/_vti_bin/ListData.svc/ChangeRules()?$filter=(Id eq 1)

Is there any way of making Id work with startswith?

  • The reason why it is not working because, startswith takes both parameter as string value and not an integer – SharePointMan Apr 28 '14 at 10:05
  • Can you explain little more in detail? – Nadeem Yousuf Apr 28 '14 at 10:10
  • the default syntax to use for startswith is" bool startswith(string p0, string p1)". ID is integer type, so you can only filter it using operators. – SharePointMan Apr 28 '14 at 10:14
  • What is the source of this information? – Nadeem Yousuf Apr 28 '14 at 10:30
  • odata.org/documentation/odata-version-2-0/uri-conventions. Also since it takes both string parameters, you can try both values with inverted comas.not sure.just a suggestion – SharePointMan Apr 28 '14 at 10:33
1

you can use the substringof clause. Like this:

$filter=substringof(Id, '1')

More details on the following link: http://wiki.sensenet.com/index.php?title=OData_REST_API

1

startsWith OData query option could not be applied to ID field since the function startsWith accepts field values of string type only (e.g. Text Field Type).

However you could use a different approach for query multiple items by ID as demonstrated below.

How to query multiple items by ID via SharePoint REST

Option 1. Specify items explicitly using chained and and or operators. Example: /_vti_bin/ListData.svc/Documents?$filter=(ID eq 1) or (ID eq 2) or (ID eq 3)

Option 2. Specify items limit in a query using top operator. Example: /_vti_bin/ListData.svc/Documents?$top=3&$orderby=ID

Option 3. Specify the range using lt, le, gt, ge operators. Example: /_vti_bin/ListData.svc/Documents?$filter=(ID ge 1) and (ID le 3)

  • Thanks @Vadim, my problem is a bit different. I am actually working on auto complete functionality. So, I can't use any of the above methods. What I am looking for is some kind of workaround so that if a user types '15', then items with ID like '15', '151', '1523' .... etc show up. – Nadeem Yousuf Apr 29 '14 at 6:00
  • @NadeemYousuf autocompelte on ID? That is a new one :) I guess you are trying to do this Client-Side with the OOTB methods available, so have you tried csom? – eirikb Apr 29 '14 at 6:52
  • Not necessarily ID, it can be any number column. I have a codeplex project for Autocomplete Lookup field. autocompletelookup.codeplex.com. It uses REST to query the list. A user opened an issue that it doesn't work when lookup field is ID. – Nadeem Yousuf Apr 29 '14 at 6:56
0

Since ID is a longint, you can't. So, you need to put it to a string field. You can't use calculated values, so a SP workflow could do the trick.

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.