Rollup Data View Web Parts Revisited

I posted back in February about using the Data View Web Part to do cross list rollups (See Rolling Up Content in SharePoint Using the Data View Web Part (DVWP)).  Since then, I’ve done quite a few of these, and I’ve been meaning for some time to post this update.  Not everything that I believed to be true in that earlier post is right all of the time.

It turns out that the CAML is the key to success with this type of DVWP.  What it amounts to is something like the following in the selectcommand.  (Note that you cannot have any of the white space or comments I show below to describe it if you want it to work!).  This is from a client example, but you should be able to get the gist of it for your situation.

<View>
  // This says to grab from all child webs recursively.
  <Webs Scope='Recursive'></Webs>
  // ServerTemplate 100 is 'General List', i.e., Custom Lists.
  // See the 'Type' attribute on the page at http://msdn.microsoft.com/en-us/library/ms462947.aspx
  // for descriptions of the various values that are available.
  <Lists ServerTemplate='100'></Lists>
  <View>
  <Query>
    <Where>
      <Eq>
        // Only grab items which have ContentType of 'Finding'. This isn't required,
        // but if you do not make it explicit, you will also get any items
        // which have all of the columns below in the <ViewFields>.
        <FieldRef Name='ContentType'/><Value Type='Text'>Finding</Value>
      </Eq>
    </Where>
  </Query>
  // In a CrossList Data Source, the <ViewFields> are what matters
  // when it comes to specifying columns.
  // <DataFields> has no effect whatsoever, and can even be removed.
  <ViewFields>
    <FieldRef Name='ID'/>
    <FieldRef Name='Title'/>
    <FieldRef Name='AuditTitleCT'/>
    <FieldRef Name='AuditorCT'/>
    <FieldRef Name='CompleteDateCT'/>
    <FieldRef Name='RiskCT'/>
    <FieldRef Name='FileDirRef'/>
   </ViewFields>
  </View>
</View>

The DataSources section will end up looking something like below:

<DataSources><SharePoint:SPDataSource runat="server" DataSourceMode="CrossList" UseInternalName="true" selectcommand="<View><Webs Scope=&quot;Recursive&quot;></Webs><Lists ServerTemplate=&quot;100&quot;></Lists><View><Query><Where><Eq><FieldRef Name=&quot;ContentType&quot;/><Value Type=&quot;Text&quot;>Finding</Value></Eq></Where></Query><ViewFields><FieldRef Name=&quot;ID&quot;/><FieldRef Name=&quot;Title&quot;/><FieldRef Name=&quot;AuditTitleCT&quot;/><FieldRef Name=&quot;AuditorCT&quot;/><FieldRef Name=&quot;CompleteDateCT&quot;/><FieldRef Name=&quot;RiskCT&quot;/><FieldRef Name=&quot;FileDirRef&quot;/></ViewFields></View></View>" id="dataformwebpart2"></SharePoint:SPDataSource></DataSources>

One other thing to note: It didn’t make one bit of difference in my testing what the WebURL was set to or even if it was there.  All items in the current Web (Site) and any below it in the Site Collection topology are returned.  You could obviously control this further by either adapting your topology or adding more constraints in your Where clause in the CAML.

Note added 23 September 2008: When you add your columns to the ViewFields section, you may see that the first underscore character is encoded as _x005F_.  In other words, a column named Expiration Date, which would normally have the internal name of @Expiration_x0020_Date is shown as @Expiration_x005F_x0020_Date.  You actually will need to change the column references in your XML to reflect this oddity.

Similar Posts

24 Comments

  1. (no name):
     
    The first thing I would check is permissions on site7.  Next, look at the list(s) that you expect to get items back from and make sure that the structure of those items matches the structure in the other lists that you are getting items back from.
     
    M.
  2. If you mean an actual calendar (the boxy view), then I think you are out of luck.  That view is a highly complex one with lots of fancy underlying logic.  I haven’t heard of anyone pulling that off, which isn’t to say that it can’t be done!
     
    M.
  3. Mark,
     Thanks for the update to the original post. Yes, this works well. I was able to consolidate all the calendar entries in one list. Now, I am looking for XSLT that will allow me to show it in Calendar view. Do you think you can help me with that? :)
  4. Hi Marc,
     
    Good posting here.
     
    I would like to know if it is possible roll-up calendar items from all sites and present it in calendar view?
     
    TIA,
    Ken
  5. I know this is an old post but it’s one of the few (only?) ones that touched on the WebURL property.

    I have all of this working properly but I would like to place the completed web part in a different place in the site, but have it reference a site (and subsites) not in the path. Consider this:

    root
    –Blogs Publishing Site
    —-Blog Site 1
    —-Blog Site 2
    —-Blog Site 3
    –Admin Site
    —-AdminTool Page (containing my web part)

    My web part displays all the subsite blogs and makes it easy to update a custom column (“IsFeatured”) on any posts within any of those blogs, from one location (otherwise, someone would have to drill into each blog and set “IsFeatured” to true or false in order to show or hide a given post on the front page). But I want this and other similar site-wide tools to reside in one place.

    My control works fine if I place it in a page under “/Blogs”, but in the AdminTool Page I can’t figure out how to tell the SPDataSource in CrossList mode to look at “/Blogs”. Any ideas at all, or am I missing something fundamental?

    1. Brett:

      Nice approach. I like what you’re doing.

      As with all things SharePoint, there’s probably more than one way to do this, but here’s an idea. Another option on Webs is Scope=SiteCollection. This says to grab content from *everywhere* in the Site Collection.

      See this MSDN article for more details:
      http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spsitedataquery.webs.aspx

      I assume that you are already filtering for the blog list type by using:

      I think that might get you what you want. Another filter which you could apply would be to filter on the path for the items themselves to limit to only items which have paths which start with ‘/Blogs Publishing Site’. (This would help if you are using blog lists somewhere other than in the ‘Blogs Publishing Site’ path.)

      Hope this helps.

      M.

  6. Well, after posting I of course kept searching and of course then found the answer. From an MSDN blog (http://blogs.msdn.com/joshuag/default.aspx), I found that he was referencing the WebUrl parameter using inside . So my working Data Source looks like:

    <SharePoint:SPDataSource runat=”server” UseInternalName=”true”
    DataSourceMode=”CrossList” Scope=”Recursive”
    SelectCommand=””
    id=”DataSrc1″>

    And I am happy. Thanks for the quick response, hope this helps somebody.

  7. I see that WordPress didn’t like my markup. The tag that’s required is:

    <SharePoint:SPDataSource runat=”server” UseInternalName=”true”
    DataSourceMode=”CrossList” Scope=”Recursive”
    SelectCommand=”< Webs Scope=’Recursive’>
    </ Webs>
    <Lists ServerTemplate=’301′ BaseType=’0′>
    </Lists>
    <View>
    <ViewFields>
    <FieldRef Name=’Title’/>
    <FieldRef Name=’ID’/>
    <FieldRef Name=’Body’/>
    <FieldRef Name=’FileRef’/>
    <FieldRef Name=’PublishedDate’/>
    <FieldRef Name=’_ModerationStatus’/>
    <FieldRef Name=’IsFeatured’/>
    <FieldRef Name=’Modified’/>
    </ViewFields></View>” id=”DataSrc1″>
    <SelectParameters>
    <asp: Parameter runat=”server” Name=”WebUrl” DefaultValue=”/Blogs/”/>
    </ SelectParameters >
    </SharePoint:SPDataSource>

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.