6

I want to fetch ID and Title of last created item from SharePoint list using REST. I am using below url but it gives me wrong item, there are more than 10k items in the list.

http://servmachine.contoso.com/_vti_bin/ListData.svc/Products?OrderBy=ID%20DSC&$top=1

9

For applying orderby and top you need to call it like this

http://servmachine.contoso.com/_vti_bin/ListData.svc/Products()?$top=1&$orderby=Id desc

MSDN

  • Sandip might want to ordered by Created or Modified instead of ID. – James Grizzle Nov 21 '14 at 15:56
  • Once you put parenthesis Products() it can be ordered by any field. – Amal Hashim Nov 21 '14 at 16:10
  • 1
    @AmalHashim I think you need ID instead of Id. @james-grizzle why would Created be better than ID, wouldn't it be the same? And Modified would not be the last created item. – eirikb Nov 21 '14 at 20:48
  • @eirikb is correct. – James Grizzle Nov 21 '14 at 21:00
  • @AmalHashim, parenthesis are not mandatory and @eirikb it is Id and not ID. FYI, orderby doesn't work if top is not used. See here: sharepoint.stackexchange.com/questions/58188/… – Nadeem Yousuf Nov 24 '14 at 6:53

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.