I have the following JSOM code:

var query = "<View><Query><Where><Eq><FieldRef Name='Category'/><Value Type='Choice'>ValueA</Value></Eq></Where></Query><ViewFields><FieldRef Name='Title'/><FieldRef Name='Value'/><FieldRef Name='Created'/></ViewFields><OrderBy><FieldRef Name='Created' Ascending='FALSE' /></OrderBy><QueryOptions><RowLimit>6</RowLimit></QueryOptions></View>"
camlQuery = new SP.CamlQuery()
items = list.getItems(camlQuery)

however the items returned don't seem to be in the order I set ...


The method of setting the query options is a little different in the Client Object Model. The correct form of your query is:

                <FieldRef Name='Category'/>
                <Value Type='Choice'>ValueA</Value>
            <FieldRef Name='Created' Ascending='FALSE' />
        <FieldRef Name='Title'/>
        <FieldRef Name='Value'/>
        <FieldRef Name='Created'/>

See this for more details: CAML and the Client Object Model.

  • Interessting - I used the CAML Designer (karinebosch.wordpress.com/2012/05/12/caml-designer), which suggested my slightly different CAML; which doesn't seem to work - at least not when using the JSOM. – nyn3x Jun 27 '12 at 11:58
  • Yes the JSCOM uses different format for the CAML. The Caml in my above answer should work with the JSCOM. – Vardhaman Deshpande Jun 27 '12 at 13:29
  • yes, it does - thx! – nyn3x Jun 28 '12 at 10:28

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.