MOSS 2007: Displaying Custom Fields in Content Query Web Parts

The Content Query Web Part (CQWP) allows you to display data from a list anywhere within a Site Collection, and it works very well to only display the data targeted for a SharePoint group when Target Audiences are enabled for rows of data in that list. However, by default the CQWP only displays the freaking ‘Title’ of the row of data, if you want to display all the other columns in the list you have to do these modifications described in the 7 steps below.  Tidbits/Fun Facts/Caveats:

  • The CQWP is only available with MOSS 2007, not with WSS 3.0!!
  • The CQWP cannot pull data from a Lookup field that allows multiple values. If you uncheck the ‘allow multiple values’ box then it works, but only 1 value of course.
  • Column Types: I copied this list:  

Display Column Type

Internal Column Type

Single line of text

Text

Multiple lines of text

Note

Choice

Choice

Number

Number

Currency

Currency

Date and Time

DateTime

Lookup

Lookup

Yes/No

Boolean

Person or Group

User

Hyperlink or Picture

URL

Calculated

Calculated

 
Holy crap, this was complicated. I was trying to learn how to do this through Heather Solomon’s blog and someone else’s blog from Microsoft and it wasn’t working right until I found this web page: http://msdn.microsoft.com/en-us/library/bb850574.aspx. The sticky point was how a column name is rendered when it has more than one word with a space between each. This is the proper way to code it for a two word situation (Department Code) in the ItemStyle.xsl file:

<td><xsl:value-of select=”@Department_x005F_x0020_Code” /></td>.  

This is the proper way to code it in the .webpart file:  
<property>Department_x0020_Code, Text;Unit_x0020_Code, Text;Department_x0020_Name, Text;Policy_x0020_Names_x0020_2009, Lookup;Policy_x0020_Names_x0020_2008, Lookup</property>
 
These are the seven overall steps (from the msdn web page above), the following sections show how you can customize the Content Query Web Part to display custom fields:
  1. Adding the Content Query Web Part to a Web page on an Office SharePoint Server 2007 site.
  2. Configuring the Content Query Web Part to work with the Project Status Reports document library and the Project Status Report content type.
  3. Exporting the Content Query Web Part to a .webpart file.
  4. Editing the exported .webpart file and setting the CommonViewFields custom property of the Content Query Web Part to request the Project Status Report content type custom fields.
  5. Editing the default XSLT transformation, which is used by the Content Query Web Part to display the Project Status Report content type custom fields.
  6. Importing the edited .webpart file to a Web page on an Office SharePoint Server 2007 site.
  7. Configuring the imported Web Part to use the new XSL style.

Leave a Reply