1

I am trying to query Sharepoint with SOAP in Powershell but am running into issues when I add more than 2 fields. What I am wondering is if there is a way to see if any of the 4 fields are Null?

When I execute this query, I get results:

<Query>
 <Where>
  <Or>
   <IsNull>
    <FieldRef Name='Field1'/>
   </IsNull>
   <IsNull>
    <FieldRef Name='Field2'/>
   </IsNull>
  </Or>
 </Where>
</Query>

However, when I execute this query, an exception is thrown.

<Query>
 <Where>
  <Or>
   <IsNull>
    <FieldRef Name='Field1'/>
   </IsNull>
   <IsNull>
    <FieldRef Name='Field2'/>
   </IsNull>
   <IsNull>
    <FieldRef Name='Field3'/>
   </IsNull>
   <IsNull>
    <FieldRef Name='Field4'/>
   </IsNull>
  </Or>
 </Where>
Adi Inbar
  • 12,097
  • 13
  • 56
  • 69
Jason W
  • 25
  • 1
  • 3

2 Answers2

1

Your CAML query is malformed. An OR tag cannot contain more than two fields, so any further fields have to be nested.

<OR >
    FEILD 4
    < OR >
        FEILD 3
        < OR >
            FELD 1
            FELD 2
        < /OR > 
    < /OR >
</ OR >

Try CAML query helper http://spcamlqueryhelper.codeplex.com/

Adi Inbar
  • 12,097
  • 13
  • 56
  • 69
Nikunj
  • 556
  • 2
  • 10
  • This is exactly what I was needing. I tried several nesting options, but this one did the trick. Thank you! – Jason W Jul 25 '14 at 21:57
0

You need to mix AND's with your OR's. For Example:

<Where>
    <And>
        <Or>
            <IsNull>
                <FieldRef Name='Field1' />
            </IsNull>
            <IsNull>
                <FieldRef Name='Field2' />
            </IsNull>
        </Or>
        <And>
            <Or>
                <IsNull>
                    <FieldRef Name='Field3' />
                </IsNull>
                <IsNull>
                    <FieldRef Name='Field4' />
                </IsNull>
            </Or>
        </And>
    </And>
</Where>

CAML query with nested AND's and OR's for multiple fields

Community
  • 1
  • 1
Justin Russell
  • 488
  • 2
  • 10
  • I've tried working with this one several times, but it keeps throwing an exception. However, the other answer with nested Or's seems to be working. – Jason W Jul 25 '14 at 21:54