0
votes

I want to apply a filter to Sharepoint list :

(((user == currentuser) && (dept == "editor")) && ((status == published) || (status == edited)|| (status == printed)))

this is my code

     <Where>
  <And>
     <And>
        <And>
           <And>
              <And>
                 <Eq>
                    <FieldRef Name='Author' />
                    <Value Type='Integer'>
                       <UserID Type='Integer' />
                    </Value>
                 </Eq>
                 <Eq>
                    <FieldRef Name='Dept' />
                    <Value Type='Text'>Editor</Value>
                 </Eq>
              </And>
              <Eq>
                 <FieldRef Name='Status' />
                 <Value Type='Text'>Published</Value>
              </Eq>
           </And>
           <Eq>
              <FieldRef Name='Status' />
              <Value Type='Text'>Draft</Value>
           </Eq>
        </And>
        <Eq>
           <FieldRef Name='Status' />
           <Value Type='Text'>Approved</Value>
        </Eq>
     </And>
     <Eq>
        <FieldRef Name='Status' />
        <Value Type='Text'>Printed</Value>
     </Eq>
  </And>

Thank you in advance for your help

1

1 Answers

0
votes

It helps to use the Or operator in your CAML and the filter values that correspond to you query. Looking at the query you have it looks like you want everything from the current user when the document in in the Editor department and it's published, edited or printed.

So essentially you have an set of conditions to or and then apply AND terms on top of. Now there may be a more efficient way to phrase this but the below meets the logical conditions you have.

<Where>
  <And>
    <And>
      <Or>
        <Or>
          <Or>
            <Eq>
              <FieldRef Name='Status' />
              <Value Type='Text'>Published</Value>
            </Eq>
          </Or>
          <Eq>
            <FieldRef Name='Status' />
            <Value Type='Text'>Edited</Value>
          </Eq>
        </Or>
        <Eq>
          <FieldRef Name='Status' />
          <Value Type='Text'>Printed</Value>
        </Eq>
      </Or>
      <Eq>
        <FieldRef Name='Dept' />
        <Value Type='Text'>Editor</Value>
      </Eq>
    </And>
    <Eq>
      <FieldRef Name='Author' />
      <Value Type='Integer'>
        <UserID Type='Integer' />
      </Value>
    </Eq>
  </And>
</Where>