Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I have a list on which I am applying the following filter (on a view) but it is not working.

if((workflow == 16 && status == published) || (workflow == 2 && status == expired))  

I am trying to apply the above filter as shown in below screenshot.
enter image description here

How do I apply this filter on this view?

share|improve this question

1 Answer 1

up vote 3 down vote accepted

Applying such complicated filter just isn't possible from UI. However, you can do it e.g. from SharePoint Designer or Powershell.

From SharePoint Designer:

  1. Open your site in SharePoint Designer
  2. Go to Lists and Libraries
  3. Select your list
  4. There is "Views" section to the right. Find your view there and click on it.
  5. Code editor will be shown.
  6. Find <Query> tag there.
  7. Inside <Query> tag you should see your conditions defined approximately as follows: <OrderBy><FieldRef Name="ID"/></OrderBy><Where><And><Or><And><Eq><FieldRef Name="Workflow"/><Value Type="Text">16</Value></Eq><Eq><FieldRef Name="Status"/><Value Type="Text">Published</Value></Eq></And><Eq><FieldRef Name="Workflow"/><Value Type="Text">2</Value></Eq></Or><Eq><FieldRef Name="Status"/><Value Type="Text">Expired</Value></Eq></And></Where></Query>

Or, in English:

  <Query>
    <OrderBy>
      <FieldRef Name="ID"/>
    </OrderBy>
    <Where>
      <And>
        <Or>
          <And>
            <Eq>
              <FieldRef Name="Workflow"/>
              <Value Type="Text">16</Value>
            </Eq>
            <Eq>
              <FieldRef Name="Status"/>
              <Value Type="Text">Published</Value>
            </Eq>
          </And>
          <Eq>
            <FieldRef Name="Workflow"/>
            <Value Type="Text">2</Value>
          </Eq>
        </Or>
        <Eq>
          <FieldRef Name="Status"/>
          <Value Type="Text">Expired</Value>
        </Eq>
      </And>
    </Where>
  </Query>

(you can format your own XML code e.g. by pasting it to Visual Studio or on http://xmltoolbox.com or by using any other online/offline tool).

This would basically mean that the condition is as follows:

(((workflow == 16 && status=='Published') || workflow==2) && status == 'Expired')

So the brackets order is incorrect.

So you should change this XML to reflect your initial idea. You will get something like this:

  <Query>
    <OrderBy>
      <FieldRef Name="ID"/>
    </OrderBy>
    <Where>
      <Or>
        <And>
          <Eq>
            <FieldRef Name="Workflow"/>
            <Value Type="Text">16</Value>
          </Eq>
          <Eq>
            <FieldRef Name="Status"/>
            <Value Type="Text">Published</Value>
          </Eq>
        </And>
        <And>
          <Eq>
            <FieldRef Name="Workflow"/>
            <Value Type="Text">2</Value>
          </Eq>
          <Eq>
            <FieldRef Name="Status"/>
            <Value Type="Text">Expired</Value>
          </Eq>
        </And>
      </Or>
    </Where>
  </Query>

After correcting the <Query> XML, don't forget to save the view.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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