CAML query with multiple OR conditions

sravya shivapuram 211 Reputation points
2021-11-22T00:25:07.62+00:00

I am using CAML query to retrieve a list of documents based on the approval status. Please see the query below - I read that it's not allowed to put more than two conditions in one condition group ( AND | OR). So I grouped only 2 OR conditions together - This does work but is returning irrelevant results ( it is also retrieving the documents with approval status = 'None') I have tried numerous ways but cannot get to what that I am looking for.

<Query>
   <Where>
       <Or>
       <Or>
           <eq>
               <FieldRef Name="ppprovalType" />
               <Value Type="Choice">Approve</Value>
             </eq>
             <eq>
                 <FieldRef Name="ApprovalType" />
                 <Value Type="Choice">Approve w/contingencies</Value>
             </eq>
         </Or>
         <eq>
             <FieldRef Name="ApprovalType" />
             <Value Type="Choice">Change Needed</Value>
         </eq>
       </Or>
   </Where>
</Query>

Also used the 'Neq' to list out the remaining statuses but didn't work either.

What is the right way to retrieve a document whose approval status is either '1' or '2' or '3'? Any help is greatly appreciated. Thank you in advance.

Microsoft 365 and Office SharePoint Development
Microsoft 365 and Office SharePoint For business Windows
0 comments No comments
{count} votes

Accepted answer
  1. RaytheonXie_MSFT 40,471 Reputation points Microsoft External Staff
    2021-11-22T07:26:21.077+00:00

    Hi @sravya shivapuram ,
    Per my test, I found that <Eq></Eq> will work and <eq></eq> always goes wrong. I have tested the following query and it works well for me. Please take a reference:

    <view><Query><Where>  
    	<Or>  
    		<Eq><FieldRef Name='ppprovalType' /><Value Type='Choice'>Approve</Value></Eq>  
    		<Or>  
    			<Eq><FieldRef Name='ApprovalType' /><Value Type='Choice'>Approve w/contingencies</Value></Eq>  
    			<Eq><FieldRef Name='ApprovalType' /><Value Type='Choice'>Change Needed</Value></Eq>  
    		</Or>  
    	</Or>  
    </Where></Query></view>	  
    

    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.