Filtering in Linked Sources using the QueryString as paramters in CAML(Select Command) and not XSLT filtering

sharepoint.stackexchange https://sharepoint.stackexchange.com/questions/4102

  •  16-10-2019
  •  | 
  •  

Question

Did anybody tried Filtering Linked Data Sources using the QueryString as paramters in CAML (Select Command) and not XSLT filters

AggregateDataSource with Parameter

<DataSources><SharePointWebControls:AggregateDataSource runat="server" IsSynchronous="false" SeparateRoot="true" id="New_x0020_Data_x0020_Source1"><sources><SharePointWebControls:spdatasource runat="server" DataSourceMode="List" UseInternalName="true" selectcommand="&lt;View&gt;&lt;Query&gt;&lt;Where&gt;&lt;Eq&gt;&lt;FieldRef Name=&quot;ID&quot;/&gt;&lt;Value Type=&quot;Counter&quot;&gt;{ID}&lt;/Value&gt;&lt;/Eq&gt;&lt;/Where&gt;&lt;OrderBy&gt;&lt;FieldRef Name=&quot;PublishedDate&quot; Ascending=&quot;FALSE&quot;/&gt;&lt;/OrderBy&gt;&lt;/Query&gt;&lt;ViewFields&gt;&lt;FieldRef Name=&quot;ContentTypeId&quot;/&gt;&lt;FieldRef Name=&quot;Title&quot;/&gt;&lt;FieldRef Name=&quot;_ModerationComments&quot;/&gt;&lt;FieldRef Name=&quot;File_x0020_Type&quot;/&gt;&lt;FieldRef Name=&quot;Body&quot;/&gt;&lt;FieldRef Name=&quot;NumComments&quot;/&gt;&lt;FieldRef Name=&quot;PostCategory&quot;/&gt;&lt;FieldRef Name=&quot;PublishedDate&quot;/&gt;&lt;FieldRef Name=&quot;_ModerationStatus&quot;/&gt;&lt;FieldRef Name=&quot;ID&quot;/&gt;&lt;FieldRef Name=&quot;ContentType&quot;/&gt;&lt;FieldRef Name=&quot;Modified&quot;/&gt;&lt;FieldRef Name=&quot;Created&quot;/&gt;&lt;FieldRef Name=&quot;Author&quot;/&gt;&lt;FieldRef Name=&quot;Editor&quot;/&gt;&lt;FieldRef Name=&quot;_HasCopyDestinations&quot;/&gt;&lt;FieldRef Name=&quot;_CopySource&quot;/&gt;&lt;FieldRef Name=&quot;_UIVersion&quot;/&gt;&lt;FieldRef Name=&quot;_UIVersionString&quot;/&gt;&lt;FieldRef Name=&quot;Attachments&quot;/&gt;&lt;FieldRef Name=&quot;FileRef&quot;/&gt;&lt;FieldRef Name=&quot;FileDirRef&quot;/&gt;&lt;FieldRef Name=&quot;Created_x0020_Date&quot;/&gt;&lt;FieldRef Name=&quot;FSObjType&quot;/&gt;&lt;FieldRef Name=&quot;FileLeafRef&quot;/&gt;&lt;FieldRef Name=&quot;PermMask&quot;/&gt;&lt;/ViewFields&gt;&lt;/View&gt;"><SelectParameters><asp:Parameter Name="ListID" DefaultValue="5A97A2C9-5609-47DE-A259-9DF3CCD3BB7D"/></SelectParameters><DeleteParameters><asp:Parameter Name="ListID" DefaultValue="5A97A2C9-5609-47DE-A259-9DF3CCD3BB7D"/></DeleteParameters><UpdateParameters><asp:Parameter Name="ListID" DefaultValue="5A97A2C9-5609-47DE-A259-9DF3CCD3BB7D"/></UpdateParameters><InsertParameters><asp:Parameter Name="ListID" DefaultValue="5A97A2C9-5609-47DE-A259-9DF3CCD3BB7D"/></InsertParameters></SharePointWebControls:spdatasource><SharePointWebControls:spdatasource runat="server" DataSourceMode="List" UseInternalName="true" selectcommand="&lt;View&gt;&lt;Query&gt;&lt;Where&gt;&lt;Eq&gt;&lt;FieldRef Name=&quot;_ModerationStatus&quot;/&gt;&lt;Value Type=&quot;Text&quot;&gt;Approved&lt;/Value&gt;&lt;/Eq&gt;&lt;/Where&gt;&lt;OrderBy&gt;&lt;FieldRef Name=&quot;Created&quot; Ascending=&quot;FALSE&quot;/&gt;&lt;/OrderBy&gt;&lt;/Query&gt;&lt;ViewFields&gt;&lt;FieldRef Name=&quot;ContentTypeId&quot;/&gt;&lt;FieldRef Name=&quot;Title&quot;/&gt;&lt;FieldRef Name=&quot;_ModerationComments&quot;/&gt;&lt;FieldRef Name=&quot;File_x0020_Type&quot;/&gt;&lt;FieldRef Name=&quot;Body&quot;/&gt;&lt;FieldRef Name=&quot;PostTitle&quot;/&gt;&lt;FieldRef Name=&quot;PostID&quot;/&gt;&lt;FieldRef Name=&quot;_ModerationStatus&quot;/&gt;&lt;FieldRef Name=&quot;ID&quot;/&gt;&lt;FieldRef Name=&quot;ContentType&quot;/&gt;&lt;FieldRef Name=&quot;Modified&quot;/&gt;&lt;FieldRef Name=&quot;Created&quot;/&gt;&lt;FieldRef Name=&quot;Author&quot;/&gt;&lt;FieldRef Name=&quot;Editor&quot;/&gt;&lt;FieldRef Name=&quot;_HasCopyDestinations&quot;/&gt;&lt;FieldRef Name=&quot;_CopySource&quot;/&gt;&lt;FieldRef Name=&quot;_UIVersion&quot;/&gt;&lt;FieldRef Name=&quot;_UIVersionString&quot;/&gt;&lt;FieldRef Name=&quot;Attachments&quot;/&gt;&lt;FieldRef Name=&quot;FileRef&quot;/&gt;&lt;FieldRef Name=&quot;FileDirRef&quot;/&gt;&lt;FieldRef Name=&quot;Created_x0020_Date&quot;/&gt;&lt;FieldRef Name=&quot;FSObjType&quot;/&gt;&lt;FieldRef Name=&quot;FileLeafRef&quot;/&gt;&lt;FieldRef Name=&quot;PermMask&quot;/&gt;&lt;/ViewFields&gt;&lt;/View&gt;"><SelectParameters><asp:Parameter Name="ListID" DefaultValue="C5635ED3-F6B9-48B3-9A79-1C2B5C256701"/></SelectParameters><DeleteParameters><asp:Parameter Name="ListID" DefaultValue="C5635ED3-F6B9-48B3-9A79-1C2B5C256701"/></DeleteParameters><UpdateParameters><asp:Parameter Name="ListID" DefaultValue="C5635ED3-F6B9-48B3-9A79-1C2B5C256701"/></UpdateParameters><InsertParameters><asp:Parameter Name="ListID" DefaultValue="C5635ED3-F6B9-48B3-9A79-1C2B5C256701"/></InsertParameters></SharePointWebControls:spdatasource></sources><aggregate><concat name="data source"><datasource name="Posts" id="0" Type="SPList"/><datasource name="Comments" id="1" Type="SPList"/></concat></aggregate></SharePointWebControls:AggregateDataSource></DataSources>

Parameter Bindings

<ParameterBindings><ParameterBinding Name="dvt_apos" Location="Postback;Connection"/><ParameterBinding Name="UserID" Location="CAMLVariable" DefaultValue="CurrentUserName"/><ParameterBinding Name="Today" Location="CAMLVariable" DefaultValue="CurrentDate"/><ParameterBinding Name="ID" Location="QueryString(ID)" DefaultValue="1"/></ParameterBindings>
Was it helpful?

Solution

You can use the values of Query String parameters by setting up parameters in your DVWP and then using those values in your filters. The net effect of this is to alter the CAML to contain the filtering.

Creation of each parameter will create a line in the ParameterBindings section like this:

<ParameterBinding Name="ID" Location="QueryString(ID)" DefaultValue=""/>

You can then use that value in your CAML, something like this:

selectcommand="&lt;View&gt;&lt;Query&gt;&lt;Where&gt;&lt;Eq&gt;&lt;FieldRef Name=&quot;ID&quot;/&gt;&lt;Value Type=&quot;Counter&quot;&gt;{ID}&lt;/Value&gt;&lt;/Eq&gt;&lt;/Where&gt;&lt;/Query&gt;&lt;/View&gt;"

OTHER TIPS

@Marc: can I access to CAMLVariable like HttpvDir or HttpPath or HttpHost, if I am creating AggregrateDataSource..?

I am not able to get any of the values for above parameters though I have declare them in ParameterBindings section..

I got it working. You need to add DataFormParameter. Please refer to http://spisnotthedevil.blogspot.co.uk/2012/12/dynamic-filter-on-linked-datasource.html for more details.

Eg:

<ParameterBindings>
   . . .
  <ParameterBinding Name=”Department” Location=”QueryString(Dept)” DefaultValue=”Human Resources”/>

      <SelectParamters>

            . . .

. . .

</SharePoint:SPDataSource>

      <SharePoint:SPDataSource . . .   SelectCommand=” . . . ” . . .>

      <SelectParamters>

            . . .

. . .

</SharePoint:SPDataSource>

Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top