0

Can someone please help me with this caml query? I have a list view and the list view should only return items created by the current user. Then I also have a textbox to provide values for Title and Comments. I am not sure why the following caml doesn't work?

<Query> <Where>
  <Or>
     <Or>
        <And>
           <Eq>
              <FieldRef Name='Author' />
              <Value Type='Integer'>
                 <UserID />
              </Value>
           </Eq>
           <Eq>
              <FieldRef Name='Title' />
              <Value Type='Text'>{Param1}</Value>
           </Eq>
        </And>
        <Eq>
           <FieldRef Name='_Comments' />
           <Value Type='Note'>{Param1}</Value>
        </Eq>
     </Or>
     <Contains>
        <FieldRef Name='RequestStatus' />
        <Value Type='Choice'>{Param1}</Value>
     </Contains>
  </Or>

{Param1} is an asp:textbox server side control with autopostback set to true.

Thanks in advance for all the help.

2 Answers 2

0

What you've got there in pseudocode is Created by User and Title = whatever OR Comments = whatever OR Request Status = whatever

Your AND is out of place. And remember to close up your where and query tags.

Remember CAML is based on pairs of statements anded/ored together.

This ors together the title and comment fields.

Then ors that answer with the status field

Then ands that whole thing with the user.

<Query> <Where>
    <And>
       <Eq>
          <FieldRef Name='Author' />
          <Value Type='Integer'>
             <UserID />
          </Value>
       </Eq>
       <Or>
            <Or>
               <Eq>
                  <FieldRef Name='Title' />
                  <Value Type='Text'>{Param1}</Value>
               </Eq>
               <Eq>
                   <FieldRef Name='_Comments' />
                   <Value Type='Note'>{Param1}</Value>
               </Eq>
            </Or>
             <Contains>
                <FieldRef Name='RequestStatus' />
                <Value Type='Choice'>{Param1}</Value>
             </Contains>
        </Or>
    </And>
    </Where>
    </Query>
0
<Where>
    <And>
        <Eq>
            <FieldRef Name="Author" LookupId="True" />
            <Value Type="Integer">
                <UserID />
            </Value>
        </Eq>
        <Or>
            <Eq>
                <FieldRef Name="Title" />
                <Value Type="Text">Test 1</Value>
            </Eq>
            <Or>
                <Eq>
                    <FieldRef Name="_Comments" />
                    <Value Type="Text">test</Value>
                </Eq>
                <Contains>
                    <FieldRef Name="RequestStatus" />
                    <Value Type="Choice">A</Value>
                </Contains>
            </Or>
        </Or>
    </And>
</Where>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.