Search code examples
javascriptjquerysharepointspservices

Define more than one <OrderBy> with SpServices, jQuery


I am not sure if this is the correct way of defining two orderby's in the query as I could not find the documentation regarding this issue. Nor did this work as expected for me.

I am trying this:

 var query = "<Query><OrderBy><FieldRef Name='Number' Ascending='true' /><FieldRef Name='Number' Ascending='true' /></OrderBy></Query>";

Solution

  • A quick search took me to this page: OrderBy Element (Query)

    <OrderBy>
      <FieldRef Name="Newcomers"/>
      <FieldRef Name="Years" Ascending="FALSE"/>
      <FieldRef Name="Location"/>
    </OrderBy>
    

    All I can say is that you're doing what the documentation shows. Have a poke around over there yourself - I can safely say you have more experience than I do with SharePoint Services.

    Edit: I doubt this makes a difference, but try defining your query like this:

    var query = '<Query><OrderBy><FieldRef Name="Number" Ascending="TRUE" /><FieldRef Name="Number" Ascending="TRUE" /></OrderBy></Query>';
    

    I just swapped the apostrophe string declaration around to use double quotes, and the case of true to TRUE.