Retrieving Tasks assigned to users or one of their groups

0 comments

Sometimes you want to retrieve all tasks that are assigned to a user or to one of the SharePoint groups the user is a member of. This quite easy to accomplish through generation of a CAML query.

Just create an Or statement for tasks assigned to the user and loop through all of the groups in the SPUser object to add those to the query.

The resulting query will look like this:

<where>
<or>
<eq>
<fieldRef Name='AssignedTo'/>
<value Type='User'>Piet van Tul</value>
</eq>
<eq>
<fieldRef Name='AssignedTo'/>
<value Type='User'>Region Controllers</value>
</eq>
<eq>
<fieldRef Name='AssignedTo'/>
<value Type='User'>Accounting department</value>
</eq>
</or>
<where>

By using this query in the QueryOverride of a Content Query Web Part you have all the power of a Content Query combined with the power of query generation.

EDIT: My collegue Wouter Lemaire pointed out that you can only specify 2 terms per Or or And element. So the above CAML could give some unexpected results.

No related posts.

Tagged , . Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>