DataZoom
Aggregate List Items Across Sites
 Send Feedback
Samples > Aggregate List Items Across Sites

Glossary Item Box

Learn how to aggregate list item data across sites and sub-sites in the same site collection using the CreateSPSiteDataQuery methods of the SPUtility context object. The CreateSPSiteDataQuery method is used to create a new instance of the SPSiteDataQuery object which can be used to...

 

  1. Aggregate data from lists of the same server template (e.g. Announcements - 106), base type (e.g. Generic), collection of list IDs, or lists with the same index.
  2. Define a list of fields and ‘Project Properties’ to read.
  3. Aggregate data from the site collection, current web or recursive webs.
  4. Filter and sort lists data using CAML.
  5. Limit the max number of rows returned by the query.

Prerequisites

This example requires one site (Home) and one sub-site (Vendors) each containing one or more Announcements lists. This example uses the following SharePoint data.

 

Site: / (Home)

    - List: Global Announcements List

        - Item: Global Announcement 1

        - Item: Global Announcement 2 

Site: /Vendors (Vendors Site)

    - List: Vendor Announcements List

        - Item: Vendor Announcement 1

        - Item: Vendor Announcement 2 

Syntax

Aggregate List Items ACross Sites Copy Code

## Setup site data query inputs
#set( $viewFieldsXml = "<FieldRef Name='Title'/><FieldRef Name='Created' />" )
#set( $listsXml = "<Lists ServerTemplate='104' />" )
#set( $websXml = "<Webs Scope='SiteCollection'/>" )
#set( $queryCaml = "<OrderBy><FieldRef Name='Created' Ascending='FALSE' /></OrderBy>" )

 

## Create the site data query   
#set( $siteDataQuery = $SPUtility.CreateSPSiteDataQuery($viewFieldsXml, $listsXml, $websXml, $queryCaml, 50) )

 

## Execute the site data query
#set( $dataTable = $web.GetSiteData($siteDataQuery) )

 

#foreach($dataRow in $dataTable.Rows)
  #beforeall
    <table class="ms-listviewtable" cellpadding="3" cellspacing="0" border="0" width="100%">
      <tr class="ms-viewheadertr">
        <th class="ms-vh2-nofilter">Title</th>
        <th class="ms-vh2-nofilter">Created</th>
      </tr>
  #odd
      <tr class="">
  #even
      <tr class="ms-alternating">
  #each
        <td class="ms-vb2">$dataRow.get_item("Title")</td>
        <td class="ms-vb2">$dataRow.get_item("Created")</td>
  #after
      </tr>
  #afterall
    </table>
  #nodata
    No announcements found
#end

Output

 

©2010 SharePoint Solutions. All Rights Reserved.