Inspecting the CAML of a Content Query Web Part

I saw a message on the twitter tag #SPHelp today from @paulschaeflein asking how to troubleshoot the Content Query Web Part. After recently rediscovering a post I’d written on a bug with the CQWP it was fresh in my memory that I’d previously had to do a similar thing. In particular I’d wanted to inspect the CAML query used by a specific web part.

Assuming that you have access to the logs it’s actually quite a straight forward process to see the query that’s being used. Here’s an example:

First I’ll create a CQWP on a page which simply goes away and gets all pages across the site collection which have ‘Glyn’ in the title and where created after the turn of the year. I set this up like so:
CQWP Configured Properties

Having done this I can now see the results as I expect:
CQWP Configured

Now assuming that I want to view the underlying CAML query that is used for this web part I simply have to look in the log files. To do this I use the essential ULS Viewer, and open up the logs so that I can see real-time results (having first ensured that I have temporarily increased the logging level to ‘verbose’).

Next I simply add a filter to the logs to see entries where the message field contains the string “<where>”. I could also filter by the Product: Web Content Management and the Category: Publishing. From here I can actually see the CAML query that is being used for my web part!

Stripping out the relevant bits of the CAML I see that in my example the query looks like this (note how it uses the GUIDs of the field names):

				<FieldRef ID="{8c06beca-0777-48f7-91c7-6da68bc07b69}" Nullable="True" Type="DateTime"/>
				<Value Type="DateTime">2011-01-01T00:00:00Z</Value>
				<FieldRef ID="{fa564e0f-0c70-4ab9-b863-0177e6ddd247}" Nullable="True" Type="Text"/>
				<Value Type="Text">Glyn</Value>
		<FieldRef ID="{8c06beca-0777-48f7-91c7-6da68bc07b69}" Nullable="True" Type="DateTime" Ascending="FALSE"/>
share and enjoy
  • Print
  • Twitter
  • Digg
  • StumbleUpon
  • Yahoo! Buzz
  • Google Bookmarks
  • Facebook

Leave a Reply

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>