1

I'm calling GetListItems via spservices, and specifying the CAMLQuery field to be the following value:

<Where>
  <Or>
   <Contains><FieldRef Name='ows_Title'/><Value Type='Text'>my search term here</Value></Contains>
  <Or>
   <Contains><FieldRef Name='ows_LinkFilename'/><Value Type='Text'>my search term here</Value></Contains>
  <Or>
   <Contains><FieldRef Name='ows_Description1'/><Value Type='Text'>my search term here</Value></Contains>
  <Or>
   <Contains><FieldRef Name='ows_Team'/><Value Type='Text'>my search term here</Value></Contains>
  <Or>
   <Contains><FieldRef Name='ows_Editor'/><Value Type='Text'>my search term here</Value></Contains>
   <Contains><FieldRef Name='ows_Keywords'/><Value Type='Text'>my search term here</Value></Contains>
  </Or></Or></Or></Or></Or></Where>

What's coming back from SharePoint is this:

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<soap:Fault>
<faultcode>soap:Server</faultcode>
<faultstring>Exception of type 'Microsoft.SharePoint.SoapServer.SoapServerException' was thrown.</faultstring>
<detail>
<errorstring xmlns="http://schemas.microsoft.com/sharepoint/soap/">Element &lt;Query&gt; of parameter query is missing or invalid.</errorstring>
<errorcode xmlns="http://schemas.microsoft.com/sharepoint/soap/">0x82000000</errorcode></detail></soap:Fault>
</soap:Body></soap:Envelope>

Clearly there's something wrong with this query, but what isn't specified by the error message. I know I'm using deeply nested Or clauses, is that a potential source of the problem, or what else about the CAMLQuery above would offend?

2

The whole Or section looks wrong, try using BIWUG CAML Designer to craft your query, then use that in your SPServices function. Also, you need to use the internal field names, not the web service returned fields (Description1 vs ows_Description1 etc).

http://www.biwug.be/resources

Typical nested Ors would look like this:

<Where>
      <Or>
         <Or>
            <Or>
               <Membership Type='SPWeb.AllUsers'>
                  <FieldRef Name='Author' />
               </Membership>
               <Eq>
                  <FieldRef Name='Field1' />
                  <Value Type='Lookup'>Something</Value>
               </Eq>
            </Or>
            <Eq>
               <FieldRef Name='Field2' />
               <Value Type='Lookup'>Something</Value>
            </Eq>
         </Or>
         <Eq>
            <FieldRef Name='Field3' />
            <Value Type='Lookup'>Something</Value>
         </Eq>
      </Or>
   </Where>
| improve this answer | |
  • Thanks; will investigate. Although unfortunately I have JS code that's generating the caml query. I'm hoping I can use this tool to figure the right way to do it, but ultimately I'll have to adapt that into the JS code, I won't be able to use this tool. Does that sound like the right approach? – FrobberOfBits Apr 15 '15 at 17:19
  • 1
    The tool will give you the correct CAML, then it'll be up to you to adapt the JS code to output the correct CAML that gets passed into your SPServices function. – Eric Alexander Apr 15 '15 at 17:24
  • Is there something specific that looks really wrong about these nested OR blocks? What is the right approach there? The tool seems to be having trouble getting through the auth layer of our sharepoint, so I'm wondering if there are general tips on what's going wrong here, other than "rewrite the query" – FrobberOfBits Apr 15 '15 at 17:33
  • The nesting looks wrong, see updated example – Eric Alexander Apr 15 '15 at 17:58
  • 1
    Also Also, you need to use the internal field names, not the web service returned fields (Description1 vs ows_Description1). – Eric Alexander Apr 15 '15 at 18:19
2

I don't think you use the correct columns' names. You're using the names as seen by the SharePoint search engine, not the internal names of the fields. For instance, ows_Title should be Title, etc.

On the other side, I don't think the nested OR are wrong here, they're just up-side-down.

| improve this answer | |

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.