Inconvenient User Tasks Web Part and how to make it display all tasks


The out of the box available User Tasks Web Part allows you to show tasks assigned to the current user. This Web Part is a great building block for end users since it doesn’t require any configuration whatsoever. All you have to do is to add it to a page and it will automatically display all tasks assigned to the current user. Unfortunately by default the User Tasks Web Part displays only tasks assigned to the current user located in tasks lists in the current Site.

The scenario

Imagine you’ve been given the assignment of creating an overview of tasks assigned to users. To make it user friendly all you want to display are the tasks for the user currently visiting the site. Although there are multiple projects where the tasks can be created you were asked to provide a single overview for the users.

Choices, choices, every time choices

Reading the first part of the requirement you might start considering using the out of the box available User Tasks Web Part, which displays a list of all tasks assigned to the current user. Each task has a link attached to it so that it’s easy for users to quickly see more information about a specific task. However, because of the last part of the requirement, you cannot really use the User Tasks Web Part: after all it displays tasks from the current site only. So what are the options?

Embrace the development

If you are a developer or a power-user you know that aggregating all tasks assigned to the current user isn’t that complicated. Depending on your experience and knowledge of the platform you might come up with a custom solution: either some using the SharePoint API or a Data View Web Part-like solution configured through SharePoint Designer.

While there is nothing wrong with any of those approaches there is an easier way to get things done, especially if all you need to do is to display tasks from all sites using the default User Experience.

Content Query Web Part almighty

Content Query Web Part (CQWP) is probably the best content aggregation solution available on the SharePoint platform. Thanks to its built-in caching mechanisms it’s very well performing and since the presentation of the aggregated data relies on XSLT you it is very flexible and can be used in virtually any situation.

The great thing about using the CQWP for this purpose is the ability of configuring it through the UI. Using the standard properties you can configure just the right query to retrieve tasks assigned to the current user. If you however would like to present the retrieved tasks similarly to the standard User Tasks Web Part, it would take quite some effort to achieve the same result.

There is yet another way to get things done without too much work.

Customization through configuration

While it might seem impossible at first, the User Tasks Web Part ships with a hidden gem that allows you to display all tasks assigned to the current user.

Let’s start with adding the User Tasks Web Part. By default it will display all tasks assigned to the current user, stored in tasks lists in the current Site.

User Tasks Web Part on a SharePoint 2010 Team Site showing one task.

Although there are is one more task assigned to the current user, stored in the Team 1 site, it is not being picked up by the User Tasks Web Part we have just added.

As mentioned before, the property that allows you to change the default behavior of the User Tasks Web Part is hidden and cannot be modified through the UI. So in order to make the User Tasks Web Part display all tasks, you need to export the Web Part and change the value in the .dwp file.

Export… menu item highlighted in the context menu of the User Tasks Web Part.

After you open the .dwp file in your favorite text editor, you have to add the following snippet just before the </WebPart> tag:

<QuerySiteCollection xmlns="http://schemas.microsoft.com/WebPart/v2/Aggregation">true</QuerySiteCollection>

The QuerySiteCollection element highlighted inside the .dwp file in Visual Studio 2010.

Important: It is important to include the xmlns attribute. If you omit it, the setting won’t work and the User Tasks Web Part will display tasks from the current site only as it does by default.

Once you do that, save the file, move back to SharePoint, upload the .dwp file and add the imported User Tasks Web Part. You should see all tasks assigned to the current user being displayed in the overview:

SharePoint 2010 Team Site with two User Tasks Web Parts. The first displays two tasks, the second one displays one task.

And that’s it: from now on, no matter where in the Site Collection a task will be created and assigned to a user, it will be displayed on the overview that you have just created.

One more important thing to notice is, that although I’ve used SharePoint 2010 as sample for this article, exactly the same approach can be used with SharePoint 2007.

Summary

Out of the box SharePoint ships with the User Tasks Web Part which allows you to display tasks assigned to the current user. By default this Web Part shows only tasks stored in the current Site. If all you need to do is to modify the overview and include all tasks from all sites in the Site Collection, the best approach is to change the value of a hidden property of the User Tasks Web Part.

Technorati Tags: SharePoint,SharePoint 2010

Others found also helpful: