2014-07-25 24 views
1

我想在Powershell中用SOAP查询Sharepoint,但是当我添加2个以上的字段时遇到了问题。我想知道的是,如果有方法可以查看4个字段中的任何一个是否为空?使用SOAP在multipe字段中查询Sharepoint的空值

当我执行此查询,我得到的结果:

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

然而,当我执行此查询时,会抛出异常。

<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> 

回答

1

您的CAML查询格式错误。 OR标签不能包含两个以上的字段,因此任何其他字段都必须嵌套。

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

尝试CAML查询助手 http://spcamlqueryhelper.codeplex.com/

+0

这正是我需要。我尝试了几个嵌套选项,但是这个做了诀窍。谢谢! –

0

你需要混合,并与您的OR的是。例如:

<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

+0

我已经尝试过多次使用这个工具,但它一直抛出异常。但是,嵌套Or的其他答案似乎正在工作。 –