2
votes

Can't figure out a good way to do this. I have a view in SharePoint that I want to filter using a query like (A and B) or (A and C). I'm trying to write this in CAML in Sharepoint Designer but am getting nowhere. This is my first time using CAML so that's not helping. Here's what I've come up with so far:

<Where>
           <And>
                <Or>
                     <And>
                          <Eq>
                               <FieldRef Name="Component" />
                               <Value Type="Text">ComponentX</Value>
                          </Eq>
                          <Eq>
                               <FieldRef Name="Review_x0020_Canceled" />
                               <Value Type="Boolean">0</Value>
                          </Eq>
                     </And>
                </Or>
                <Eq>
                     <FieldRef Name="Component" />
                     <Value Type="Text">ComponentX</Value>
                </Eq>
                <IsNull>
                     <FieldRef Name="Actual_x0020_Finish_x0020_Date" />
                </IsNull>
           </And>
      </Where>

I'd like this to display all records where (Component=ComponentX AND Review Canceled=No) or (Component=ComponentX AND Actual Finish Date=Null)

Any ideas?

2

2 Answers

1
votes

try this:

<Where>
  <Or>
    <And>
      <Eq>
        <FieldRef Name='Component' />
        <Value Type='Text'>ComponentX</Value>
      </Eq>
      <Eq>
        <FieldRef Name='Review_x0020_Canceled' />
        <Value Type='Boolean'>0</Value>
      </Eq>
    </And>
    <And>
      <Eq>
        <FieldRef Name='Component' />
        <Value Type='Text'>ComponentX</Value>
      </Eq>
      <IsNull>
        <FieldRef Name="Actual_x0020_Finish_x0020_Date" />
      </IsNull>
    </And>
  </Or>
</Where>

will return the record with the blue background color

new code caml:

<Where>
  <And>
    <And>
      <Eq>
        <FieldRef Name='Review_x0020_Canceled' />
        <Value Type='Boolean'>0</Value>
      </Eq>
      <Eq>
        <FieldRef Name='Component' />
        <Value Type='Text'>ComponentX</Value>
      </Eq>
    </And>
    <IsNull>
      <FieldRef Name='Actual_x0020_Finish_x0020_Date' />
    </IsNull>
  </And>
</Where>
0
votes

Your logic

(Component = ComponentX AND Review Canceled = NO) OR 
    (Component = ComponentX AND Actual Finish Date = NULL)

is equivalent to

Component = ComponentX And (Review Canceled = NO OR Actual Finish Date = NULL)

which would be this CAML query:

<Where>
  <And>
    <Eq>
      <FieldRef Name="Component" />
      <Value Type="Text">ComponentX</Value>
    </Eq>
    <Or>
      <Eq>
        <FieldRef Name="Review_x0020_Canceled" />
        <Value Type="Boolean">0</Value>
      </Eq>
      <IsNull>
        <FieldRef Name="Actual_x0020_Finish_x0020_Date" />
      </IsNull>
    </Or>
  </And>  
</Where>