Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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()
camlQuery.set_viewXml(query)
items = list.getItems(camlQuery)
context.load(items)

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

share|improve this question
add comment

1 Answer 1

up vote 5 down vote accepted

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

<View>
    <Query>
        <Where>
            <Eq>
                <FieldRef Name='Category'/>
                <Value Type='Choice'>ValueA</Value>
            </Eq>
        </Where>
        <OrderBy>
            <FieldRef Name='Created' Ascending='FALSE' />
        </OrderBy>
    </Query>
    <ViewFields>
        <FieldRef Name='Title'/>
        <FieldRef Name='Value'/>
        <FieldRef Name='Created'/>
    </ViewFields>
    <RowLimit>6</RowLimit>
</View>

See this for more details: http://karinebosch.wordpress.com/2012/02/03/caml-and-the-client-object-model/

share|improve this answer
    
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
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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