Friday, 23 March 2012

How to use Content Query Webpart in SharePoint


In this article I would detail more on how to use Content query webpart in SharePoint 2010, it has got a bit more enhanced and advanced than the CQWP (content query webpart) you found in SharePoint 2007; however you can easily get wrong on understanding how this works because of several reasons.
I had spent time looking around  and wasting a lot of time to find articles on this, so I thought better to put together all these in a single place for you all...

If you search for CQWP mostly you would hit the MSDN site however you still might need to find other articles to understand it and  get a grip. The primary question is …..

      Q. Where do you use a CQWP, and basically When will you use this webpart?

Ans.      Content Query Web Part could be used to create custom views of data that is queried from many sources, and present that data all in one place. After you add the Content By Query Web Part to a Web page, you can customize the Web Part's querying behaviours  and also the look and feel to display data appropriately.
It can also be used in many scenarios, some examples below:

+ If you have a site collection with a root site and you want to bring in and display the most recent blog posts from all blog sites within its own site collection…. Yes you can use CQWP for this

+ If you want to bring in and show all the events in a group calendar on the root site from the sub-sites created below….. CQWP will do

+ You can also bring in data views from a document library or lists and filter it and show it dynamically.

So here I will guide you through on how to configure a CQWP and to bring in data with two examples :
Example 1
Imagine that you want show a Group-Events calendar which will show  all the events from the calendars which are added in site and sub-sites within a Site-collection. It would be really nice if we could do this easily ….without any custom coding; yes you can do that with CQWP  or to aggregate data from all the "Announcement " list  which exist in sites and sub- sites of a site collection and to show that on the root site of the site collection.

Now lets crack on with the Group-Events calendar…. You can achieve this in less than 5 minutes !!!!!

Step 1.
Open up your SharePoint team site or a publishing site .

Step 2.

Insert  a CQWP webpart from the webparts list, you can find it in the "Content Rollup" category ( If you cannot find the webpart it means you have not enabled "SharePoint Publishing Infrastructure " feature . Search in internet or review this link to resolve http://social.technet.microsoft.com/Forums/en-US/sharepoint2010setup/thread/cd1203e6-0054-4e19-a690-7ef545d48290/
Step 3.
Once the webpart is added on to the site,  Click on the "Edit Webpart" and this will open up the CQWP tool part pane.
Step 4.

Basically the key useful sections of this tool webpart are below:


  1. Query Section : In this section you will be able to mention the source of data which you can bring in, you can also mention about the filters you can apply on the data source.
  1. Presentation Section : In this section you will be able to mention about the "Grouping, Sorting" , Styles and most importantly "the fields to display" on the CQWP.




Step 5.
In the Query section, Select the first option  "Show items from all sites in this site collection". In the List type select "calendar" . In the "Grouping and Sorting" select "Group Items by" - Title
 Leave all the other fields as in the Query section as it is.
Step 6.
In the Presentation section select  Group Style > Banded, if you are looking for a bit of styling.
In the Fields to display leave as it is, this is one of the key things ; the fields you see are the default values which are going to be in the  CQWP, you can add more values to it however it needs XSLT editing.
Step 7.
That’s it ……….all done, now you can see your CQWP showing all the events in the site collection grouped and styled.
Now play around  change the grouping fields or filter there are many things you can do with it…..
Example 2

Now If you want to show contents from a specific list can you do something similar ?.... Yes
I will take you through the steps quickly…..


Step 1.
Create a custom list with site columns on it, I have quickly created a list with 2 columns on it "Name" and "Description".

Note: DO NOT create new columns from a list if you want to display your own fields. There is an MSDN article says about it but always remember to create Site columns for this.

Step 2.
Once your list is created, Click on the "Edit Webpart" and this will open up the CQWP tool part pane.

Step 3.
Expand "Query" section and select the source list from the browse button
Step 4.
Expand the "Presentation" section and go to the "Field to Display" section. By default SharePoint provides 4 fields to display  Link, Image, Title and Description.  Put "TitleDescription" in Title and "EmpName" in Description.


Step 5.

That's all the Content Query webpart will start displaying the values from these fields.


Note : Even though  the help on the "Fields to display" says [Depending on the scope of your query, select one or more site or list columns whose values you want to show in the following display slots for this style, separating entries with a semicolon. To specify a column from a particular group, type the name of the group in square brackets after the column name. Ex: Column[Group]] you can display multiple fields by semi columns on these fields, this is NOT QUITE TRUE.

If you want to add more custom columns then you have to edit the XSLT style sheet file on the style library.
Hope this article helped you to get some insight on CQWP

CQWP is quite powerful, you can use this for many things -

If you like to format Content Query Webpart and give it a great look, check this Article : 

http://sharepointlogics.com/2014/02/sharepoint-2010-content-query-web-part.html
















Here is another one, How to use CQWP for a News Scroller , Scrolling Announcement - 

http://sharepointlogics.com/2014/07/sharepoint-scrolling-announcement-news.html









Here are some links and site you can use to have a look :

Here is an Example of CQWP usage, the widget you see on the site is CQWP
Eric: Swenson


Friday, 16 March 2012

Unable to Display List in SharePoint Page

You would have got an error something similar to this, at least once in your sharepoint journey ...

"The page you selected contains a list that does not exist. It may have been deleted by another user"
This is primarily happening because of a reference missing or corrupted webpart, So quick tip to get out of this situation first:

Step 1. Try and find which list is causing the issue, so get to the SharePoint maintanence page
if you append "?contents=1" to your site URL you will get into the maintanence page
Eg. ?contents=1

Step 2. Once the webpart is removed try and scope where the problem is, you can use SharePoint logs for this.

I thought of jotting this out, as a quick pointer in panic mode.... 

Thursday, 15 March 2012

How to show a column value based on other columns in a SharePoint Custom List

In one of the SharePoint list i was asked to provide a custom value based on the values inputed on the other columns. You might have faced a similar situation sometimes, this was thought to be a customisation, but i found that this could easily be acheived by using formula column in SharePoint.

I would run through the steps here :
Column 1
Column 2
Column 3 (Formula Column)
Value 1
Value 2
If Value in both Columns =”OK”
If  No Values in both columns =”Not Applicable”
 Value 1
 Value


So if Column1 and 2 has both values then Column 3 value = "OK" else "Not Applicable"

I tried couple of variations and was able to find a solution for this using the formula below :
=IF(COUNTA([Column 1],[Column 2])=0, "Not Applicable", "OK")

Step 1.
Create a new column in a list
Step 2.
Select the "Type of Information as" :
Calculated (calculation based on other columns)
Step 3.
In the Formula column insert the appropriate columns and add the formula (you may have to edit the formula based on the columns you are having)
Step 4.
Select the datatype returned from the formula (the values returned as results, in this case "single line of text" as i have given text values ("Not Applicable", "Yes")
Step 5.
Click OK and add the column


The page will throw validation errors if there are any problems with the formula you input.


You can use "CountA" parameter to check and count on non-blank columns, you can use this formulat in differnt variance to achieve the specific need you have.

Also Refer to the microsoft site for other formula parameters :