0

we have webpart that fetch the data from the sharepoint list

camlQuery.set_viewXml("<View></View>); 

now i am trying to do sort the display by enddate (ascending order)

camlQuery.set_viewXml("<View><Query><OrderBy><FieldRef Name='EndDate' /></OrderBy></Query></View>"); 

i am using the above caml query but it is not working , can you please help me out.

my code

function GetCTItems() { var context = new SP.ClientContext(); var oList = context.get_web().get_lists().getByTitle('sharepointLst'); var camlQuery = new SP.CamlQuery(); //camlQuery.Query=("<OrderBy><FieldRef Name='EndDate' Ascending = 'FALSE'/></OrderBy>"); camlQuery.set_viewXml("<View><Query><OrderBy><FieldRef Name='EndDate' Ascending='True' /></OrderBy></Query></View>"); var CTCollection = oList.getItems(camlQuery); context.load(CTCollection); context.executeQueryAsync(function () { var htmlString = ""; var listItemEnumerator = CTCollection.getEnumerator(); 

3 Answers 3

0

Try to use Ascending='True' as the following

camlQuery.set_viewXml("<View><Query><OrderBy><FieldRef Name='EndDate' Ascending='True' /></OrderBy></Query></View>"); 
1
  • Comments are not for extended discussion; this conversation has been moved to chat. Commented Oct 18, 2017 at 19:28
0

To get the correct CAML, create a view that meets your criteria in SharePoint on the list and then you could use SharePoint Client Browser at https://github.com/bramdejager/spcb/blob/master/README.md to get the actual CAML for the view.

1
  • i am using CAML builder , <Query><OrderBy><FieldRef Name='EndDate' /></OrderBy> this is working in CAML builder, but not in code i don't know why Commented Oct 18, 2017 at 18:52
-1

Or you can create the view you want in the User Interface in SharePoint List as you would manually do and extract the CAML Query from the browser directly (easiest way IMHO):

https://powershellscripts.github.io/articles/en/SharePointOnline/CAMLQueryForListView/

enter image description here

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.