Content Query Web Part - Field Types

Over the last few months I have had to configure various Content Query Web Parts (CQWP) to provide portal rollups that can be pre-packaged and re-configured in the SharePoint UI instead of having to use SharePoint Designer when using Data View Web Parts.   

I could go into the basics of setting up a CQWP, but since others have done it for us I’ll just provide some link love here.  Even though this post if fairly old it provides a TON of value for those getting started with the CQWP, but the main thing I find missing is how to identify the items needed in the CommonViewFields property.  You can find the internal field name pretty easy by going to your list settings, and then look at the URL when you hover over the column you want to identify.  The Field Query String parameter gives you the internal name you need.

 

Internal Column Name

Now that you have the internal name for the columns you need, now you need the column type.  I haven’t been able to find a decent resource for all of the column types, so I figured this is where I needed to list them all out:

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

 

Of course these are all the default column types you can create, however there are some others, like the Publishing columns such as:

Display Column Type

Internal Column Type

Publishing Image

Image

Publishing HTML

HTML

Another nice way to see what these values are would be to use PowerShell.  I will often drop into PowerShell and look at the fields in a specific list to view the internal name, along with other variables, the following lines will output a table of all fields associated with a list and the Display Name, Internal Name, Display Column Type, and the Internal Column Type:

 

[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")

 

$site = new-object Microsoft.SharePoint.SPSite("http://moss150")

$web = $site.OpenWeb()

$list = $web.Lists["CQWP"]

$list.Fields | Format-Table Title, InternalName, TypeDisplayName, TypeAsString

 List Fields - PowerShell

Having these items should now set you up to have all the information you need to customize your Content Query Web Part.  Just create a customized template in the ItemStyle.xsl (or create your own custom XSL file and link to it using the ItemXslLink property in your .webpart file) to render the information you need and you should be ready to start utilizing the infamous Content Query Web Part.

 

Sample Web Part

["Brian"]

 

NOTE:  If you are going to use any of the ddwrt commands that you might be used to using SharePoint Designer to format dates and such, make sure to include the appropriate stylesheet in the header of your XSL file:

 

xmlns:ddwrt="http://schemas.microsoft.com/WebParts/v2/DataView/runtime"


Posted 12-01-2008 1:36 PM by Brian Caauwe

Comments

dat0 wrote re: Content Query Web Part - Field Types
on 12-09-2008 1:05 AM

Could you provide more detail on how to customize ItemStyle.xsl?

Brian Caauwe wrote re: Content Query Web Part - Field Types
on 12-09-2008 7:27 AM

If you take a peek at this post:

blogs.msdn.com/.../configuring-and-customizing-the-content-query-web-part.aspx

It helps walk though all of the components of the ItemStyle.xsl and how to create your own template that you can use.  

If you are unsure on how to use some of the markup, sometimes using SharePoint Designer (in a data view web part) can help you determine how to create the markup, or how to format an item from text to a number, or how to do the DateTime formatting.

If you want the specific example of the template I used in this post, let me know and I'll email you that sample XSL

["Brian"]

AlMo wrote re: Content Query Web Part - Field Types
on 01-13-2009 12:53 PM

What is up with the Query portion being limited to only three "filtered" subqueries? And just like FrontPage over the 10 years of its dumb life, if you set up a query to say "USER contains 'this guy'" OR "USER contains 'that guy'" AND "EndDate greater or equal to Today" then Sharepoint "tidies up" the environment by putting the ORs first, invalidating the logic, when you click on "Exit Edit Mode".

Confluence: SharePoint Development Wiki wrote Getting the Field by the Internal Name
on 02-02-2009 6:23 AM

The Column Display names on a SharePoint List are different to the Internal Names: e.g. "My Column 1" you will get "Myx0020Columnx00201" From Web UI You can get the Internal Names from the url when you go and edit individual Columns on a List....

cw300 wrote re: Content Query Web Part - Field Types
on 02-03-2009 2:01 PM

Prefacing that I don't know XSLT and only a limited bit about XML, I've followed the instructions at blogs.msdn.com/.../configuring-and-customizing-the-content-query-web-part.aspx and the relevant post on Heather Solomon's site (I don't have SPDesigner though) to customize a CQWP. I'm fairly confident I've identified accurately the column fields I want to retrieve, but the three fields don't appear in the CQWP. My custom item style does appear in the drop-down, but nothing occurs when I choose it. Though the ecm blog doesn't mention it, Heather says to "Wrap HTML around the xsl:value tag to format the data". I'm wondering if this is my problem because I'm unsure how to go about that. I've learned HTML and css on my own to accomplish most of what I've needed to do, so I'd appreciate if someone can point me in the right direction to get this working.

Brian Caauwe wrote re: Content Query Web Part - Field Types
on 03-10-2009 9:17 PM

The CQWP is limited to the 3 filter values in the toolpane.  If you know CAML you are able to use the QueryOverride parameter of the webpart (only available by exporting the webpart and modifying the .webpart file) to define a more complicated query

["Brian"]

Brian Caauwe wrote re: Content Query Web Part - Field Types
on 03-10-2009 9:21 PM

For showing the values that you have defined in the CommonViewFields area of the webpart, you need to have something like:

<xsl:value-of select="@Description"/> in your HTML markup.

I would recommend starting with an existing ItemStyle template and just replacing where they are referencing things like "$Title" and such.

The biggest thing is, first you need to make sure your CQWP has the CommonViewFields set (using Site Column internal names) AND reference those fields in the ItemStyle template you choose.

["Brian"]

Inetium, LLC. Site Information