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();
0

Try to use Ascending='True' as the following

camlQuery.set_viewXml("<View><Query><OrderBy><FieldRef Name='EndDate' Ascending='True' /></OrderBy></Query></View>");
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.

  • 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 – karthik Oct 18 '17 at 18:52

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.