Global Tasks View Web Part

Some time ago, someone asked on Microsoft Forum how he can create the Global Tasks list, which will be showing all the tasks assigned to the current user from all the sites. This “Blog” entry has been created in response to his question. Hope you will enjoyed.

Steps:

Open the main site, and from Site Actions select Edit Page

Click Add a Web Part, then select Tasks from the list and click Add button

Site with Web Part should look like on the following screenshot

Open SharePoint Designer

Select File | Open Site and in Site Name type http://localhost and click Open

Double click on Default.aspx site, so it will open for edit (select Split view mode) – if you like you can check out the file before opening or even do the copy of the it and open the copied one so you will not mess with default.aspx file.

In Design view, right click on the Tasks web part, and select Convert To XSLT Data View

This operation will convert ListViewWebPart to DataFormWebPart, and will generate XSLT code for showing tasks from Tasks list on the main site.

In the Code view find following lines of code

<SharePoint:SPDataSource runat="server" IncludeHidden="true" SelectCommand="&lt;View&gt;&lt;Query&gt;&lt;OrderBy&gt;&lt;FieldRef Name=&quot;Modified&quot; Ascending=&quot;FALSE&quot;/&gt;&lt;/OrderBy&gt;&lt;Where&gt;&lt;Or&gt;&lt;Neq&gt;&lt;FieldRef Name=&quot;Status&quot;/&gt;&lt;Value Type=&quot;Text&quot;&gt;Completed&lt;/Value&gt;&lt;/Neq&gt;&lt;IsNull&gt;&lt;FieldRef Name=&quot;Status&quot;/&gt;&lt;/IsNull&gt;&lt;/Or&gt;&lt;/Where&gt;&lt;/Query&gt;&lt;/View&gt;" id="datasource1" DataSourceMode="List" UseInternalName="true">

<InsertParameters>

<asp:Parameter DefaultValue="{F6532524-58C1-4A47-83B2-AE2C87C6E89F}" Name="ListID"></asp:Parameter>

</InsertParameters>

<UpdateParameters>

<asp:Parameter DefaultValue="{F6532524-58C1-4A47-83B2-AE2C87C6E89F}" Name="ListID"></asp:Parameter>

</UpdateParameters>

<DeleteParameters>

<asp:Parameter DefaultValue="{F6532524-58C1-4A47-83B2-AE2C87C6E89F}" Name="ListID"></asp:Parameter>

</DeleteParameters>

<SelectParameters>

<asp:Parameter Name="ListID" DefaultValue="{F6532524-58C1-4A47-83B2-AE2C87C6E89F}"/>

<asp:QueryStringParameter Name="RootFolder" querystringfield="RootFolder" type="String"/>

<asp:Parameter Name="MaximumRows" DefaultValue="20"/>

</SelectParameters>

</SharePoint:SPDataSource>

SPDataSource specify list data source. From the SPDataSource we will need to change two properties: SelectCommand and DataSourceMode.

Change DataSourceMode to CrossList

New SelectCommand should look like this:

<View>

<Query>

<OrderBy>

<FieldRef Name="Modified" Ascending="FALSE"/>

</OrderBy>

<Where>

<Or>

<Neq>

<FieldRef Name="Status"/>

<Value Type="Text">Completed</Value>

</Neq>

<IsNull>

<FieldRef Name="Status"/>

</IsNull>

</Or>

</Where>

</Query>

</View>

If you would like to change it/modified it, best would be to change it now. Do change it in Design View click on the little arrow in the top right corner of web part and select Filter:....

New window will be showed in which you can specify more advanced filter.

Ok, so if you’re done with filter let’s do final changes the Select Command; however If you changed the filter, please copy the new Select Command to Notepad and keep it for reference.

Now, we need to add two tags just after a View tag of Select Command:

<Webs Scope="Recursive"></Webs>

<Lists ServerTemplate="107" BaseType="0"></Lists>

Webs tag with Scope attribute define where to look for the data:

·         FilesOnly — Show only the files of a specific folder.

·         Recursive — Show all files of all folders.

·         RecursiveAll — Show all files and all subfolders of all folders.

Lists tag define what type of list we should query. More information about server templates can be found here (BaseType) and here (Templates).

So, the SelectCommand should look like this now

<View>

<Webs Scope="Recursive"></Webs>

<Lists ServerTemplate="107" BaseType="0"></Lists>

<Query>

<OrderBy>

<FieldRef Name="Modified" Ascending="FALSE"/>

</OrderBy>

<Where>

<Or>

<Neq>

<FieldRef Name="Status"/>

<Value Type="Text">Completed</Value>

</Neq>

<IsNull>

<FieldRef Name="Status"/>

</IsNull>

</Or>

</Where>

</Query>

</View>

Now we need to change every <, > and “ to &lt;, &gt;, &qout; and just in case, delete line breaks, so the Select Command will look like this

&lt;View&gt;&lt;Webs Scope=&quot;Recursive&quot;&gt;&lt;/Webs&gt;&lt;Lists ServerTemplate=&quot;107&quot; BaseType=&quot;0&quot;&gt;&lt;/Lists&gt;&lt;Query&gt;&lt;OrderBy&gt;&lt;FieldRef Name=&quot;Modified&quot; Ascending=&quot;FALSE&quot;/&gt;&lt;/OrderBy&gt;&lt;Where&gt;&lt;Or&gt;&lt;Neq&gt;&lt;FieldRef Name=&quot;Status&quot;/&gt;&lt;Value Type=&quot;Text&quot;&gt;Completed&lt;/Value&gt;&lt;/Neq&gt;&lt;IsNull&gt;&lt;FieldRef Name=&quot;Status&quot;/&gt;&lt;/IsNull&gt;&lt;/Or&gt;&lt;/Where&gt;&lt;/Query&gt;&lt;/View&gt;

Now, if you save the Default.aspx file, and you will still not see any Tasks, you should update Data Set. Therefore, in SharePoint Designer open task Pane with current data sources.

Click on the tasks, the new window will pop up

Click on Fields

You should see many fields on the left, now click twice ok, and the current data source will refresh. Now you will see the tasks in web part! Cooool :)

However, we still have few issues:

1)      Link to the tasks is not pointing to the proper site.

2)      All tasks are showed (not only tasks assigned to current user).

3)      Tasks list should still exists on the main site – however we should not need it.

Firstly let’s solve number 2; secondly we will dive into XSLT code to solve number 1 and finally we will make our global tasks web part independent of existing lists:)

To solve issue no 2, we need to click on the little arrow in the top right corner of the web part in design view and select following option

In Filter add new filter with And option (I’ve deleted Status IS Null criterion):

Click OK. Save the file and see if the changes works :)

Now it’s time solve issue with the links! For this, we will need to dive into XSLT code. Find lines with the code for ctx.displayFormUrl and ctx.editFormUrl (displayFormUrl and editFormUrl should exist twice in the code):

ctx.displayFormUrl = &quot;<xsl:value-of select="$URL_DISPLAY" />&quot;;

ctx.editFormUrl = &quot;<xsl:value-of select="$URL_EDIT" />&quot;;

Change dose lines to:

ctx.displayFormUrl = &quot;&lt;xsl:value-of select="@EncodedAbsUrl" /&gt;&lt;xsl:value-of select="substring-after(@FileDirRef, '#')" /&gt;/DispForm.aspx&quot;;

ctx.editFormUrl = &quot;&lt;xsl:value-of select="@EncodedAbsUrl" /&gt;&lt;xsl:value-of select="substring-after(@FileDirRef, '#')" /&gt;/EditForm.aspx&quot;;

Now find line with code:

<a onfocus="OnLink(this)" href="{$URL_Display}?ID={@ID}" onclick="GoToPage('{$URL_Display}?ID={@ID}');return false;" target="_self">

and change it to:

<a href="{@EncodedAbsUrl}{substring-after(@FileDirRef, '#')}/DispForm.aspx?ID={@ID}" target="_self">

<xsl:attribute name="onclik">

            GoToPage("<xsl:value-of select="@EncodedAbsUrl" /><xsl:value-of select="substring-after(@FileDirRef, '#')" />/DispForm.aspx?ID=<xsl:value-of select="@ID" />"); return false;

      </xsl:attribute>

Save the file and we’re done with another issue :) If you like you can test it. Create the task on the subsite, assign yourself to the task and go to the main page and – click on the task – it should transfer you to the sub site :)

Ok, let’s solve our last issue – tasks list on the main site. Before we began, please copy the code of the webpart to notepad to have a copy of it – just in case :)

From SPDataSource tag, remove following lines:

<SelectParameters>

  <asp:Parameter DefaultValue="{F6532524-58C1-4A47-83B2-AE2C87C6E89F}" Name="ListID"></asp:Parameter>

  <asp:Parameter DefaultValue="20" Name="MaximumRows"></asp:Parameter>

</SelectParameters>

<UpdateParameters>

  <asp:Parameter DefaultValue="{F6532524-58C1-4A47-83B2-AE2C87C6E89F}" Name="ListID"></asp:Parameter>

</UpdateParameters>

<InsertParameters>

  <asp:Parameter DefaultValue="{F6532524-58C1-4A47-83B2-AE2C87C6E89F}" Name="ListID"></asp:Parameter>

</InsertParameters>

<DeleteParameters>

  <asp:Parameter DefaultValue="{F6532524-58C1-4A47-83B2-AE2C87C6E89F}" Name="ListID"></asp:Parameter>

</DeleteParameters>

 

Now, search for the GUID (in my case F6532524-58C1-4A47-83B2-AE2C87C6E89F), and replace it to empty string (this GUID should be listed in two places only).

Now save the file :) and we’re done :) we can delete the Tasks list on the main site and the web part will still works :)

Opublikowane 03 lipca 08 11:32 przez Gutek

Powiadamianie o komentarzach

Jeżeli chciałbyś otrzymywać email gdy ta wypowiedź zostanie zaktualizowana, to zarejestruj się tutaj

Subskrybuj komentarze za pomocą RSS

Komentarze:

# Santhosh said on września 10, 2008 05:17:

Hi,

i need to display subsite title also....

kindly help me....

# Gutek said on września 10, 2008 17:56:

@Santhosh

Hi,

There is an issue with getting a Web Name/Site Name from SDP. I was trying different ways to get it from WebId (which is returned in the query), but MOSS/WSS does not provide any JavaScript functionality to return a title. If you would look at the creating of the ctx object, you will see that there is a variable called SiteTitle which should contain a site name. However, SDP is assigning literally “web” string instead of SiteTitle :(

There are two workarounds that I can think of:

1) Create a JavaScript to call GetWeb Webs.asmx web service method, which is taking an URL to site and returns information about the web including title. This solution required an extra webservice.htc file from Microsoft and aprox 3 methods: Init, Get and Results. Web URL can be obtained by parsing Item URL (returned by query). However I do not think that this is a good solution.

2) Own webpart using SPGridView to create a similar table – this solution will be much better then (1)  but it needs Server access and some development. If you really needs it, just let me know and I will try to find some time to create it for you.

Hope this helps.

Cheers,

  Jakub G

# Ivy said on października 9, 2008 19:55:

Hi,

This works great except at the bottom right corner of the tasks list where it 1-11.  If you click that link, you'll get 12 -21 except that the exact same tasks are listed.  It doesn't change the tasks.  Can this be fixed?

# Gutek said on października 10, 2008 17:31:

Hi Ivy,

I will try to recreate the webpart during this weekend. As I remember once I had similar issue like you, but during writing this article, I had created aprox 3 web parts, and for sure, paging in the last one was working - the last version has been deployed on client intranet web site and I am sure they would contact me if smth were not working properly.

Cheers,

  Jakub G

# Gutek said on października 12, 2008 22:47:

Hi Ivy,

Finally I found some spare time to spend on the web part. My whole example is based on default view of the Tasks List Web Part. To enable paging I need to recreate the web part but this time I’ve used View editor on the page (Modified Shared Web Part | Selected View | Edit current view) to specify the view on the web part in which I’ve added a query attribute to show only my tasks, and to limit items 5 per page. Then I’ve converted the Web Part to XSLT Data Web Part.

And as I can see from the article the images that I’ve been used has been from the first web part without paging :( Sorry for that :( however during writing of the article I was changing some properties and then I just forgot to include them in the description.

Hope that explanation above will solve all your issues.

Cheers,

  Jakub G

# Ivy said on października 13, 2008 14:58:

Hmmm.. well, I'm a sharepoint novice so I'm not certain how to fix the problem based on the above information.  I'm sorry.  Do you mind giving me a little more detail?

# Gutek said on października 13, 2008 16:44:

Hi Ivy,

Yup.

1)      Create a Tasks list on your site;

2)      Add a Tasks Web Part to Default.aspx or on other page (Web Part Page). This web part will be showed after you create a Tasks list and it will be avaliable in web scope;

3)      Click Modified Shared Web Part to open a toolpart on the right side of the screen;

4)      First drop down rendered in the toolpart (Selected View) will contain informations regarding View, just below the dropdown you will have a link “Edit the Current View”, click on it – Edit view page will be showed;

5)      On edit view page, select what columns you would like to include in the we web part, then go to Filter section and select “And” radio button then from dropdown select “Assigned to” is equal to: [Me] – with brackets;

6)      Then in section Item Limit type a number describing how many items you would like to have on the page and select radiobutton: Display items in batches of the specified size. And click “OK” button on the bottom of the page

7)      Now again open a Modify Shared Web Part toolpart, and from second drop down select: No toolbar;

8)      Click OK

9)      Open SharePoint Designer

10)   Open a page which contains yours webpart

11)   Right-click on the web part and select “Convert to XSLT…”

12)   Add this informations to SelectCommand just after &lt;View&gt;

&lt;Webs Scope=&quot;Recursive&quot;&gt;&lt;/Webs&gt;&lt;Lists ServerTemplate=&quot;107&quot; BaseType=&quot;0&quot;&gt;&lt;/Lists&gt;

13)   Then update ctx.displayFormUrl and ctx.editFormUrl as post describe

14)   At the end Save the page and enjoy XSLT Web Part with paging

15)   If everything works, you can now reopen a page in SharePoint Designer and do the last steps of the article – removing guids – this will make your’s web part idependent of the Tasks lists.

Hope this helps, if not just let me know and I will try to post a article with screenshots.

Cheers,

   Jakub G

# Ivy said on października 13, 2008 21:22:

Thanks.  I will give it a try and let you know.

# Ivy said on października 14, 2008 17:36:

This is not working for me...

If I change the DataSourceMode to CrossList, then the tasks show up but you can not page through them.  They have the same issue...

If i leave the DataSourceMode as List, then there are no tasks listed...

# Gutek said on października 16, 2008 22:52:

Hi Ivy,

I’m completely brainless, I’m writing an article which use CrossList and then I do not use this param anywhere... instead I’m using List :(

During last two days I’ve done some testing and the issue is that, when you change DataSourceMode from List to CrossList, SharePoint is not sending paging parameters into database, and is using SPSiteDataQuery method instead of SPQuery method.

This means that paging will not be done with pure transforming of the web part, but can be created with some creativity. DataFormWebPart is using XML and XSLT to produce the output to the user. Paging controls created by default from SDP are using PostBack javascript method with parameters that are ignored by code.

If you have aprox 1-2 hours you could create paging by yourself. First we need to add RowLimit (do not add Paged attribute to RowLimit) tag to SelectCommand in View tag, this will limit the items showed to Number, then by JavaScript and XSLT modification we could implement paging.

Cheers,

   Jakub G

# Ivy said on października 20, 2008 16:59:

Thanks for the response... That all sounds very complicated.  Perhaps if you have spare time, you could add the instructions on how to do this.  i do have 1 to 2 hours for this.  I really do appreciate all the time you have taken so far to troubleshoot my issue.

# Gutek said on października 20, 2008 22:22:

Hi Ivy,

I have better idea, I will create a web part from code, crate a package and I will post it here so there will not be any more issues with the XSLT.

Just let me know if the code Web Part will be ok with you, as some times you just do not have to have appropriate permissions to deploy it

Cheers,

  Jakub G

# Ivy said on października 21, 2008 16:05:

That would be great.  Thanks so much!

# Santhosh said on listopada 11, 2008 11:03:

Why you are remove the GUID,may i know the reason please...

# Stephanus Natawardaja said on listopada 20, 2008 14:44:

Thank you, it works. Thanks for putting the effort to screenshot the steps, really useful.

# Gutek said on listopada 20, 2008 21:11:

@Santhosh

if you will remove GUID's the web part will not be "connected" to any of the list. Therefore you will be able to place it on the completely new site without modifications. Otherwise, the code will be trying to access the list that dose not exist :(

@Stephanus

glad it worked for you! :)

# Brandt Fuchs said on lutego 13, 2009 17:00:

Great Post!

# Gutek said on lutego 19, 2009 09:57:

@Brandt

Thanks :)

# Santhosh said on kwietnia 2, 2009 05:30:

Gr8 Post it's very much use full for me...

thanks Gutkowski

# Sean said on maja 19, 2009 03:53:

Thank you ....   I was trying to link announcement Title   Directly to AllItems page, I used your code to remove '#' stng...... Everything is working now.

Dataview

Title

Hyperlink

{@EncodedAbsUrl}{substring-after(@FileDirRef, '#')}/AllItems.aspx

Text To display---> :)

# Roman S. said on listopada 17, 2009 08:53:

Hi Jakub!

Nice post! I have a question, if I do like you described, will it be possible to export this web part and import in different server? I think it has different GUIDs and this is usefull if you have SPD on the server only.

Thanks, Roman

# Gutek said on listopada 17, 2009 16:40:

Hi Roman,

Try to replace GUIDs in SPDataSource with empty string. This should make webpart as independent solution.

Let me know if this works for you.

PS.: pls use this url: http://blog.gutek.pl/post/2008/07/04/Global-Tasks-View-Web-Part.aspx as usually I'm not monitoring my old blog.

Cheers,

  Jakub G

Co o tym myślisz?

(wymagane) 
(opcjonalne)
(wymagane) 

  
Wprowadź kod: (wymagane)