var restURLAuthors = _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/getbytitle('GoGreenReport')/items?$select=EncodedAbsUrl,FileRef&$filter=Project_x0020_Name eq '"+$("#ddnProjectName").val()+"'";

i want to add order by descending order of items? Where and how to write order by in this code specifically?

  • The above code along with other code adds item of attachment of a form to a library, taking project name as primary key , but with same project name multiple attachments are getting saved and when viewed its showing the oldest one, i want to view the latest one? – OM-ॐ Mar 6 '17 at 10:51

You should add order by in the REST query itself as below:

/_api/web/lists/getbytitle('GoGreenReport')/items?$select=EncodedAbsUrl,FileRef&$filter=Project_x0020_Name eq '"+$("#ddnProjectName").val()+"'&$orderby=Created desc

Here, i have appended $orderby=Created desc, you can also use $orderby=Modified desc or any other custom field with its internal name. In case if you want the latest one, you can also use $orderby=ID desc

  • I tried this whole code = var restURLAuthors = _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/getbytitle('GoGreenReport')/items?$select=EncodedAbsUrl,FileRef&$filter=Project_x0020_Name eq '"+$("#ddnProjectName").val()+"'&$orderby=ID desc"; BUT this doesnt work, am i doing something wrong? @gautam sheth – OM-ॐ Mar 7 '17 at 4:23
  • it works for me, i dont think what you are doing is wrong. Log the results in console and check – Gautam Sheth Mar 7 '17 at 10:04
  • Ok man no prob thanks for the help – OM-ॐ Mar 7 '17 at 11:21

Like the comments said, it is all done in the URI

SharePoint endpoints are ODATA endpoints

Search has different syntax

iREST

  • Thanks for the reply but i want specific answer to the code line as i have provided, if you could write me the script code itself it would be better. – OM-ॐ Mar 7 '17 at 4:42
  • i just wanted one specific line of code . Well there's world full of people like you anyways – OM-ॐ Mar 7 '17 at 11:23
  • That was a good compliment to yourself. i appreciate – OM-ॐ Mar 8 '17 at 4:15
  • the SharePoint REST API Overview link is going to SharePoint Workflow fundamentals.. docs.microsoft.com/en-us/sharepoint/dev/general-development/… – Abdul Hameed Aug 8 at 6:42

Your Answer

 
discard

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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