Displaying Columns in a Crosslist DVWP

I’ve alluded to this in the past, but I had a client situation in the last few days that brought it top of mind again. One of the quirks of a Crosslist DVWP is that you *must* specify all columns you would like to display in the CAML for the Data Source. You can add any column in the XSL you want, but if they aren’t explicitly specified in the CAML, you will get blank results.

Here’s an example. Say you want to gather the latest announcements from across the Site Collection for display on the Home Page of your Intranet. You’re displaying the latest 5 announcements, but you realize that annoucements that are expired are still showing up. So, you add a filter to the row select, as below, and you’re not seeing what you’d expect.

<xsl:variable name="Rows" select="/dsQueryResponse/Rows/Row&#91;
    (ddwrt:FormatDateTime(string(ddwrt:Today()), 1033, 'yyyyMMdd') >=
    ddwrt:FormatDateTime(string(@Expires), 1033, 'yyyyMMdd')) or
    string-length(@Expires) = 0
  ]"/>

You’ll need to add an explicit FieldRef for the Expires column in your CAML, as below.  (I’ve added carriage returns and white space into the CAML above for readability, but you can’t have them in your DVWP.)

<SharePointWebControls:SPDataSource
  runat="server"
  DataSourceMode="CrossList"
  SelectCommand="
    <View>
      <Webs Scope='SiteCollection'></Webs>
      <Lists ServerTemplate='104'></Lists>
      <ViewFields>
        <FieldRef Name='ID'/>
        <FieldRef Name='Title'/>
        <FieldRef Name='Body'/>
        <FieldRef Name='FileDirRef'/>
        <FieldRef Name='Created'/>
        <FieldRef Name='Author'/>
        <FieldRef Name='Expires'/>
        <FieldRef Name='PermMask'/>
      </ViewFields>
    </View>"
  UseInternalName="true"
  ID="dataformwebpart5">
</SharePointWebControls:SPDataSource>

Once you add the FieldRef to the CAML, the Expires column values are available for use in your filter.

Keep in mind that you need to be careful what you add into your <Viewfields> section. If you add a FieldRef for a column which doesn’t occur in *all* of the items which you want to retrieve, you will, in effect, be adding a filter to the CAML. Only items which have all of the columns specified in the FieldRefs will be returned.

Similar Posts

31 Comments

  1. well..

    What I want is to get a table that has, for example, a datetime column and so on for numbers or other types, but after an intensive search it seems like this is by design.. :/

  2. Hi

    I think I have found an issue with the cross list DVWP content rollup.

    1) Previously, I built a lovely CQWP dashboard to roll up all tasks that hold a custom content type. Was working fine until the client I am working with requested that the tasks can have muli selection “AssignedTo” fields.
    In which case the the column is set blank by SharePoint. Damn!
    2) Ok then tried a DWWP with this SPDataSource in CrossSite mode

    SharePoint:SPDataSource runat=”server” DataSourceMode=”CrossList” SelectCommand=”<View><Webs Scope=’Recursive’></Webs><Lists ServerTemplate=’107′></Lists><ViewFields><FieldRef Name=’Title’/><FieldRef Name=’ContentType’/><FieldRef Name=’AssignedTo’/></ViewFields>

    3) I f found that I want to include the “AssignedTo” field in ViewFields AND the tasks contain multiple assigned users. ThenSharePoint will simply remove them the result set. If I delete <FieldRef Name=’AssignedTo’/> in the above statement the task will appear in my results set

    Isn’t SharePoint great!
    Anyone got any ideas…. SPServices to the rescue…???????

  3. Hi Marc,

    thanks for your helpful posts on this subject! One thing I can’t get to work is:
    – In a site collection there’s a sub site e.g. /sales.
    – Then there’s another sub site e.g. /controlling with several document libraries.
    Now on the sales site I’d like to have a DVWP that shows all documents in the libraries of the controlling sub site.

    So far no success – I have a feeling that the DVWP only works top down but not sideways? (I added WebURL of course)

    Hopefully I didn’t miss any hint about this on your posts or in the comments…

    Thanks, Bernhard :-)

    1. Bernhard:

      If you are using the WebURL, it should work for any other site within the same Site Collection. DVWPs cannot use lists or libraries as DataSources if they are outside the current Site Collection. Make sure that you’ve got the WebURL set correctly. I prefer not to use links relative to the current site, e.g., “../../siteb” and usually use the path from the root site, like “/sites/sitea/siteb”.

      M.

  4. One quick question. In the above caml at the very top of this blog.

    Can I replace

    With

    Basically, I want to get all columns from all subsites in site collection which belong to a specific content type. How can I ask DVWP to show data of a specific content type

    1. Deepak:

      Your CAML didn’t make it through, but yes, you can filter on the ContentType by adding a Where clause for it. ContentType is just a column on the lists which have Content Type Management enabled. Bew sure to pay attention to the warning I give at the very bottom of the post.

      M.

  5. Hi Marc

    Have a short question, that you may know how to answer

    Basically I’m looking up a Project Summary List from multiple subsites. On the parent (rollup) site I use the crosslist functionality and works great, but on the parent site I also have a list with program reference (i.e. 1 program can have multiple projects) I have tried doing a connection between the program list and the project list (which has a reference to Program (text)) but I do not seem to be able to filter the rollup list based on the program selected. Any Pointers?

  6. Hi Marc, thanks for posting, I’m trying to use a query string variable to filter
    a crosslist data view and I’m unable to do so, any ideas?

    1. Guy:

      You can definitely do this by creating a Query String parameter and then setting a filter in the CAML using its value. I usually set up this type of filter before I turn on CrossList mode because SharePoint Designer will do it for me up to that point.

      M.

      1. Hi Marc,
        Thanks for replying, I’ve created the data view with my query string filtering and then changed it to a crosslist type, and it worked!

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.