I want to get all the items from my list, like this (A&B) AND (C&D), but my CAMLquery doesn't seem to work, here is what I've tried so far:

var camlQuery = new SP.CamlQuery(); camlQuery.set_viewXml( "<View>" + "<Query>" + "<Where>" + "<And>" + "<And>" + "<Eq><FieldRef Name='Prioritet'/><Value Type='Text'>A</Value></Eq>" + "<Eq><FieldRef Name='Status'/><Value Type='Text'>B</Value></Eq>" + "</And>" + "<And>" + "<Eq><FieldRef Name='Prioritet'/><Value Type='Text'>C</Value></Eq>" + "<Eq><FieldRef Name='Status'/><Value Type='Text'>D</Value></Eq>" + "</And>" + "</And>" + "</Where>" + "</Query>" + "</View>");

  • 1
    This won't work since this CAML query is checking if the column Prioritet and Status have 2 different values in an item i.e. it's checking if Prioritet has values A and C for the same item which is impossible. I'd suggest reformulating your query. – Akhoy Aug 10 '15 at 14:36
  • as say @uberz91, this should be Or instead an AND For example: <Or><And></And><And></And></Or> – Marco Aug 10 '15 at 14:49

the syntax is each < and> statement content 2 queries.

section <and> is one query in another <and> statement

change the query to:

"<View>" +
  "<Query>" +
    "<Where>" +
        "<And>" +
            "<And>" +
                "<And>" + <------first
                    "<Eq><FieldRef Name='Prioritet'/><Value Type='Text'>A</Value></Eq>" + <----- 1
                    "<Eq><FieldRef Name='Status'/><Value Type='Text'>B</Value></Eq>" + <------2
                "</And>" +
                "<Eq><FieldRef Name='Prioritet'/><Value Type='Text'>C</Value></Eq>" + <----- second
            "</And>" +
            "<Eq><FieldRef Name='Status'/><Value Type='Text'>D</Value></Eq>" +
        "</And>" +
    "</Where>" +
  "</Query>" +
  • The query syntax is correct. Main <And> contains two child <And> tags, and both child tags contain two <Eq> tags. Only problem is in contradictory conditions which your answer doesn't fix. – dstarkowski Jul 27 '16 at 12:30

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.