0

I'm trying to add another OR condition in my CAML Query below, but nothing seems to be working. Can someone help? Please see attached picture of the library. I am trying to get the highlighted data. Here is the CAML query. Library Name and Level stays the same. I need to grab the 1st row, 3rd and 4th row. The first attempt I am trying to get the exact person (Marshall, Kim), then I am saying give me data where Line=Pure and Any Local is Yes (not working but it should give me Sandoz, Newman), then also give me where Any Line is yes and Any Local is Yes for Packaging with Level A. (Howey, Laurel).

enter image description here

<Query>
  <ViewFields>
    <FieldRef Name="AssignedTo" />
  </ViewFields>
  <Where>
      <And>
         <Eq>
            <FieldRef Name='Library' />
            <Value Type='Lookup'>Packaging</Value>
         </Eq>
         <And>
            <Eq>
               <FieldRef Name='Level' />
               <Value Type='Choice'>A</Value>
            </Eq>
            <And>
               <Eq>
                  <FieldRef Name='Line' />
                  <Value Type='Lookup'>PURE</Value>
               </Eq>
               <Eq>
                  <FieldRef Name='Place' />
                  <Value Type='Lookup'>Vincente, New Port, CA</Value>
               </Eq>
            </And>
         </And>
 </And>
 <And>
<Or>
    <And>
      <And>
        <And>
          <Eq>
            <FieldRef Name='Library' />
            <Value Type='Lookup'>Packaging</Value>
          </Eq>
          <Eq>
            <FieldRef Name='Level' />
            <Value Type='Choice'>A</Value>
          </Eq>
        </And>
        <Eq>
          <FieldRef Name='Line' />
          <Value Type='Lookup'>PURE</Value>
        </Eq>
      </And>
      <Eq>
        <FieldRef Name='AnyPlace' />
        <Value Type='Boolean'>1</Value>
      </Eq>
    </And>
</Or>
      </And>

  </Where>
</Query> 
0

Instead of providing so many conditions, below query can work and give you exact same results.

As per what I see in the list data you have shared, I have drafted this.

<Query>
<ViewFields>
    <FieldRef Name="AssignedTo" />
</ViewFields>
<Where>
    <And>
        <Eq>
            <FieldRef Name='Library' />
            <Value Type='Lookup'>Packaging</Value>
        </Eq>
        <And>
            <Eq>
                <FieldRef Name='Level' />
                <Value Type='Choice'>A</Value>
            </Eq>            
            <Or>
                <Eq>
                    <FieldRef Name='Line' />
                    <Value Type='Lookup'>PURE</Value>
                </Eq>
                <And>
                    <Eq>
                        <FieldRef Name='AnyLine' />
                        <Value Type='Boolean'>1</Value>
                    </Eq> 
                    <Eq>
                        <FieldRef Name='AnyLocal' />
                        <Value Type='Boolean'>1</Value>
                    </Eq>
                </And>
            </Or>
        </And>
    </And>
</Where>

Please note: column names are correctly used as per your list.

If you understand the concept on how to write CAML queries, you will not need any tool. Read my blog on understanding dynamic queries

7
  • Thanks Gaurravs, I am getting "Sandoz, Newman", "Howey, Laurel" and "Shield, Brook Ann (BK)" but result should be "Marshall, Kim", "Sandoz, Newman", "Howey, Laurel"
    – Amber
    Aug 19 '21 at 4:01
  • can you try update one
    – Gaurravs
    Aug 19 '21 at 4:15
  • Cool. Now it's working. Thank you So much.
    – Amber
    Aug 19 '21 at 4:22
  • I tried using saketa and u2u caml builder but it doesn't formulate the query like you provided. What if I want have more things to add to query? what tool can I use?
    – Amber
    Aug 19 '21 at 4:30
  • Please see the updated answer. I have added a link
    – Gaurravs
    Aug 19 '21 at 5:36
0

The following code worked.

<Query>
<ViewFields>
    <FieldRef Name="AssignedTo" />
</ViewFields>
<Where>
    <And>
        <Eq>
            <FieldRef Name='Library' />
            <Value Type='Lookup'>Packaging</Value>
        </Eq>
        <And>
            <Eq>
                <FieldRef Name='Level' />
                <Value Type='Choice'>A</Value>
            </Eq>            
            <Or>
                <Eq>
                    <FieldRef Name='Line' />
                    <Value Type='Lookup'>PURE</Value>
                </Eq>              
                    <Eq>
                        <FieldRef Name='AnyLine' />
                        <Value Type='Boolean'>1</Value>
                    </Eq>                 
            </Or>
        </And>
    </And>
</Where>

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.