Content Query Web Part, QueryOverride and sorting by site
Hello,
I want to display documents from various sub-sites in my portal. These documents must be grouped by site and only documents created in the last 7 days should appear in the CQWP.
The first difficulty I encountered was that I cannot apply a filter like " date created< today - 7" in the tool pane of CQWP. So I searched the web and found that I can create a custom query by exporting the web part and changing the
QueryOverride property. Thing is that you cannot specify a CAML group clause in the QueryOverride property. It is just not supported.
It seems though (thanks to this post: http://social.msdn.microsoft.com/forums/en-US/sharepointdevelopment/thread/92e335ad-48f6-4572-a314-752c8b41ef8f) that if you specify a "order by" clause for the field you want to group by, then you can use
this field in the group by section of the CQWP tool pane. Thus, I need to sort my results by site (because I want to group by site afterwards). But how do I do that?
After another long research, I found out (http://msdn.microsoft.com/en-us/library/ff380147%28office.12%29.aspx#odcsp2007CustomizeCWQP_CustomizingUsingtUIwebpartFile) that I have to specify the
ViewFieldsOverride property in order to include the original site that my document comes from. And in the property I have to include the following property:
<ProjectProperty Name="Title"/>. But still I cannot see how I will use it in my OrderBy clause of the
QueryOverride property... The field does not display to the list of available fields and when I use
ProjectProperty.Title in my OrderBy clause the CQWB returns nothing...
I have lost 3 days for a thing that should be easy to do. Can you help me with this please?
September 8th, 2010 10:35am
Hi,
If you want your CQWP to be grouped by site name, you can set the properties of your CQWP: Modify Shared Web Part>Presentation>in the “Group items by”
dropdown list, select “<Site>”, it will get the web part grouped by site name.
For displaying documents created in the last 7 days, you should customize the web part using QueryOverrid property, the sample code is below:
<property name=QueryOverrid type=string>
<![CDATA[
<Where>
<Gt>
<FieldRef Name="Created" Nullable="True" Type="DateTime"/>
<Value Type="DateTime"><Today OffsetDays="-7"/></Value>
</Gt>
</Where>
<OrderBy>
<FieldRef Name="Created" Nullable="True" Type="DateTime"
Ascending="FALSE"/>
</OrderBy>
</Query>]]>
</property>
For more information about customizing CQWP, please refer to:
http://msdn.microsoft.com/en-us/library/aa981241.aspx
Hope it helps.Xue-Mei Chang
Free Windows Admin Tool Kit Click here and download it now
September 10th, 2010 12:05am
Nope. As I mentioned in my first post, this does not work. If you order by Created date in the QueryOverride property, grouping by site does not work; You cannot change the CQWP property in the tool pane anyway.
As I said above I need to order by site in the QueryOverride property but I don't know how.
September 17th, 2010 3:27am
Thanks to reading this I ended up trying:
<property name="QueryOverride" type="string"><![CDATA[<Where><Gt><FieldRef Name="PublicationDate" /><Value Type="DateTime"><Today OffsetDays="-7" /></Value></Gt></Where><OrderBy><ProjectProperty Name="Title" Ascending='True'/><FieldRef Name="PublicationDate" Ascending="False" /></OrderBy>]]></property>
This seems to work. :)
Free Windows Admin Tool Kit Click here and download it now
May 27th, 2012 8:41pm