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 query but I am not sure if it does what I really want:

   <Where>
      <And>
         <Contains
            <FieldRef Name='Phase' />
            <Value Type='MultiChoice'>Design</Value>
         </Contains>
         <And>
            <Contains>
               <FieldRef Name='Process' />
               <Value Type='Choice'>Blueprint</Value>
            </Contains>
            <Or>
               <Contains>
                  <FieldRef Name='Document_x0020_Type' />
                  <Value Type='Choice'>Procedure</Value>
               </Contains>
               <Or>
                  <Contains>
                     <FieldRef Name='Document_x0020_Type' />
                     <Value Type='Choice'>Policy</Value>
                  </Contains>
                  <Contains>
                     <FieldRef Name='Document_x0020_Type' />
                     <Value Type='Choice'>Template</Value>
                  </Contains>
               </Or>
            </Or>
         </And>
      </And>
   </Where>

I want to get all documents from a library where the

Phase = Design
Process = Blueprint
AND
Document type is either Procedure, Policy or Template.

In my first query I had Process = Start up and it gave me all the correct documents but when I changed it to Blueprint (no document has this Process as meta data yet) it returned half of all my documents.

Any ideas?

Thanks in advance.

share|improve this question
    
your first contains tag is missing a ">" –  David Lozzi Jan 11 '12 at 12:43
    
You need to clarify what the filter is as its ambiguous as written. Is it Phase = Design AND Process = Blueprint AND (Document Type = Procedure OR Document Type = Policy OR Document Type = Template) ? –  Ryan Jan 11 '12 at 12:55
    
yes you are correct Ryan –  John Jan 12 '12 at 0:31

4 Answers 4

It migth be more efficient to use Camlex.NET. It more understandable for new to SharePoint developers.

Stramit SharePoint Caml Viewer migth be helpfull if you tried to write caml by hands, nor using UI or C# code.

share|improve this answer
1  
+1 to Camlex.NET, very cool tool. –  Kai Jan 11 '12 at 12:55

Always use the U2U Caml Query builder to test your CAML queries. Check it out.

share|improve this answer
    
Did you notice that your first "<Contains" tag for design does not close properly with ">". Was that a typo? –  Deepu Nair Jan 11 '12 at 12:04
1  
FYI.. you can edit your answer to include more info instead of posting a comment. :) –  Kit Menke Jan 11 '12 at 14:34

First thing is that you're using the Contains operator and not Equals which may give strange results. - e.g. both "PolicyTemplate" and "Template" contain "Template" - only you can tell us if this is what you want.

That CAML breaks down to this (excuse using = in place of contains for readability)

Phase = Design
AND
Process = Blueprint
AND
(Document Type = Procedure OR Document Type = Policy OR Document Type = Template)

Which is probably what you described in your question (it's a little ambiguous as written)

share|improve this answer

Try something like this:

 <Where>
      <And>
         <Contains>
            <FieldRef Name='Phase' />
            <Value Type='MultiChoice'>Design</Value>
         </Contains>
         <And>
            <Contains>
               <FieldRef Name='Process' />
               <Value Type='Choice'>Blueprint</Value>
            </Contains>
            <In>
              <FieldRef Name='Document_x0020_Type' />
              <Values>
                <Value Type='Choice'>Procedure</Value>
                <Value Type='Choice'>Policy</Value>
                <Value Type='Choice'>Template</Value>
              </Values>
            </In>
         </And>
      </And>
   </Where>
share|improve this answer

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.