开发者

Need Help w/ SharePoint CAML Query

Here's what I'm doing (this is a quick search on Google and just one of the first results):

http://msdn.microsoft.com/en-us/library/cc300163(v=office.12).aspx

My databound DropDownList items looks like this:

<listitem>All Providers</listitem>
<listitem>Provider 1</listitem>
<listitem>Provider 2</listitem>

My current CAML query in the view looks like:

<Query>
 <Where>
  <And>
   <Or>
    <Eq>
     <FieldRef Name="Status" />
     <Value Type="Lookup">Submitted</Value>
    </Eq>
    <Eq>
     <FieldRef Name="Status" />
     <Value Type="Lookup">In Progress</Value>
    </Eq>
   </Or>
   <Eq>
    <FieldRef Name="Provider"/>
    <Value Type="Text">{Param1}</Value>
   </Eq>
  </And>
 </Where>
 <OrderBy>
  <FieldRef Name="ID" Ascending="FALSE"></FieldRef>
 </OrderBy>
</Query>

What I NEED is this...

In psuedocode:

If {Param1} equals "All Providers" just filter on Status where Status is equal to "Submitted" or "In Progress" else if {Param1} is not equal to "All Providers" filter on Status and Provider where Status is equal to "Submitted" or "In Progress" and Provider is equal to {Param1}

How do I put this into View XML schema?

I know it can be done as Microsoft already uses it in SharePoint and there's 3rd-party controls that do it.

For example...

1) In SP, click on "Lists" in the left nav menu.

2) To the far right, under the search box', you'll see "View:" with a dropdown.

3) Based on which view you choose, the URL's querystring contains "BaseType" that changes to the value of y开发者_如何学Pythonour choice. If "All Site Content" is chosen, the "BaseType" is left out of the querystring.

Thanks, Joshua


First off, I think you are better off adding a filter webpart for the Provider field, as this allows you to not filter with a blank value.

If you must have a parameter that filters on "All Providers" you can create a calculated field on the list call AllProviders say, with the formula:

="All Providers"

This then allows your query clause to be entered thusly:

<Query>
  <Where>
    <And>
      <Or>
        <Eq>
          <FieldRef Name="AllProviders"/>
          <Value Type="Text">{Param1}</Value>
        </Eq>
        <Eq>
          <FieldRef Name="Provider"/>
          <Value Type="Text">{Param1}</Value>
        </Eq>
      </Or>
      <Or>
        <Eq>
          <FieldRef Name="Status"/>
          <Value Type="Lookup">In Progress</Value>
        </Eq>
        <Eq>
          <FieldRef Name="Status"/>
          <Value Type="Lookup">Submitted</Value>
        </Eq>
      </Or>
    </And>
  </Where>
</Query>

The Status field will always match either "In Progress" or "Submitted".

If your parameter = "All Providers" then you will match the calculated field, otherwise you will match on the Provider field.

Note that this does prevent you from having a Provider call "All Providers".

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜