Archive for March, 2012

SharePoint: Content Query Web Part, more than three filters, QueryOverride and Logs

Scenario:

We need to get list items from all lists in a site collection based upon five conditions. OOTB content query web part (CWQP) provides three filters at max. The way foreword is to write a CAML query and put it inside QueryOverride property. To do this, you need to export OOTB CQWP web part. Open it in notepad or any XML viewer tool and set the property.

We wrote following CAML Query and set the QueryOverride property.

<property
name=QueryOverride
type=string ><![CDATA[

<Where>

<Or>

<And>

<And>

<Eq>

<FieldRef
Name=AnnouncementPropagate
Nullable=True
Type=Boolean/>

<Value
Type=Boolean>1</Value>

</Eq>

<Eq>

<FieldRef
Name=Region
Nullable=True
Type=Choice/>

<Value
Type=Choice>XXXXXXX</Value>

</Eq>

</And>

<Gt>

<FieldRef
Name=Expires
Nullable=True
Type=DateTime/>

<Value
Type=DateTime>

<Today/>

</Value>

</Gt>

</And>

<And>

<Eq>

<FieldRef
Name=Region
Nullable=True
Type=Choice/>

<Value
Type=Choice>
XXXXXXX</Value>

</Eq>

<Gt>

<FieldRef
Name=Expires
Nullable=True
Type=DateTime/>

<Value
Type=DateTime>

<Today/>

</Value>

</Gt>

</And>

</Or>

</Where>

]]></property>

An Or operator with three and two ANDs. Uploaded the web part and selected first option “Show items from all sites in this site collection”. After clicking “Apply”, web part display following error:

There is a problem with the query that this Web Part is issuing. Check the configuration of this Web Part and try again.

Resolution:

Tried different options and found out if we select a single list, web part works fine and if we select other two options, web part display above error.

SharePoint write the actual query created by selecting filters in the tool part of CQWP to the LOG file. So, we first configured three filters for three AND’s and copy the query from the Log file. Then, configured two filters for two ANDs and copy the query.  Joined them with Or and it did the trick.

Comments (4)

SharePoint: Remove Page node from breadcrumb

Scenario:

We were using breadcrumb and wanted to remove “Pages” library link from breadcrumb.

Resolution:

The control we were using was:

<asp:SiteMapPath
SiteMapProvider=”SPContentMapProvider” id=”ContentMap” SkipLinkText=”” RenderCurrentNodeAsLink=”false”
NodeStyle-CssClass=”ms-sitemapdirectional” runat=”server”/>

One way of removing the “Pages” node is to use “CurrentNavSiteMapProviderNoEncode” instead of “SPContentMapProvider”. Also, make sure that you have checked “Show Pages” under “Site Settings -> Navigation ->Current Navigation”.

This approach has one drawback that if you are using OOTB Left Navigation, then, pages will also start appearing in the “Left Navigation”. In order to avoid this, we are left with jQuery. Below is the snippet to accomplish above.

First include jQuery in your page:

<script
src=”http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js”></script>

Add you control as:

<asp:SiteMapPath
SiteMapProvider=”SPContentMapProvider” id=”ContentMap” SkipLinkText=”” RenderCurrentNodeAsLink=”false” 
NodeStyle-CssClass=”ms-sitemapdirectional” runat=”server”/>

Add following after the control

<script
type=”text/javascript”>

$(“Span[id=’ctl00_ContentMap’]”).children().each(function(){

if($(this).text()==’Pages’)

{

$(this).next().remove();

$(this).remove();

}

</script>

Leave a Comment

SharePoint: Reduce space b/w webparts

Scenario:

We need to reduce space b/w webparts

Resolution:

SharePoint add a div after webaprt with class “ms-PartSpacingVertical” which has margin-top property set to 12px. Add class with the same name and make margin-top zero. In our scenario, webparts were added inside div with id “middle”, so we added following class

#middle .ms-PartSpacingVertical{

    margin-top: 0px !important;

}

Leave a Comment