SharePoint: Issue with $top in ListData.svc

Hi Friends,

While working on SharePoint REST API’s in SP 2013 I come across a scenario where I need to filter on date column, I found solution to use /_vti_bin/ListData.svc service to filter based on date column like following, we can’t use RESTful call in date filtering:

  1. var date = new Date();  
  2.   
  3. var stringUrl=_spPageContextInfo.webAbsoluteUrl+"/_vti_bin/ListData.svc/EventsCalendar?$filter=StartTime+ge+datetime'"+date.toISOString()+"'&$select=Title,Description,Path,Id,StartTime&$orderby=StartTime&$top=3";  

When I tried this I was getting data in browser but not using JavaScript code which is using $.ajax call to get and read the response.

After analyzing I found that $top is the culprit in my case and found following workaround.

When we use $top we will get the result date in ‘data.d’ like following:

  1. var resultsArray = data.d;  

If you want old JS code ‘data.d.results’ to work as is with $top we need to use $inlinecount=allpages in URL call like following-

  1. var date = new Date();  
  2.   
  3. var stringUrl=_spPageContextInfo.webAbsoluteUrl+"/_vti_bin/ListData.svc/EventsCalendar?$filter=StartTime+ge+datetime'"+date.toISOString()+"'&$select=Title,Description,Path,Id,StartTime&$orderby=StartTime&$top=3&$inlinecount=allpages";  

Happy coding.!!
Ebook Download
View all
Learn
View all