TFS Query: get only topmost elements assigned to me

1.4k Views Asked by At

I am trying to build a tfs query, which will return only the topmost items that are assigned to me. Examples:

  • UserStory (US) is assigned to me and contains tasks that are assigned to me => query returns only the US
  • US is assigned to someone else, but it contains tasks that are assigned to me => query returns the tasks
  • US is assigned to me, but tasks are assigned to someone else => query returns the US

I struggling to figure out, how to access the parent of a task or maybe this isn't even the right approach. I am working with VS and TFS 2010. Ideas?

[EDIT] Another idea would be to write a wiql query, that finds all items assigned to me and than checks if the link has some properties, but iam not sure about that. In TFS2013 there supposed to be something similar ("match top-level workitems first"), unless this is just a sorting option.

1

There are 1 best solutions below

8
On BEST ANSWER

This is not possible with one query, at least you need 2, because you can't combine link filters with parts of a query:

  • Flat List

WorkItemType = UserStory AND AssignedTo = @ME

  • Work Items and Direct Links

WorkItemType = Task AND AssignedTo = @ME

Filters for linked work items:

WorkItemType = UserStory AND AssignedTo <> @ME

Return all top level work items

The first query will just list all User Stories assigned to you, no matter if something is linked or not. The second query will list all Task that are assigned to you, but have no UserStory linked that is assigned to you.

[EDIT]

Another option could be to combine both queries, but I can't test it in my environment:

  • Work Items and Direct Links

(WorkItemType = Task OR WorkItemType = User Story) AND AssignedTo = @ME

Filters for linked work items:

WorkItemType = UserStory AND AssignedTo <> @ME

Return all top level work items

This will list all User Stories and Tasks that are assigned to you, but have no parent User Story linked.

[EDIT2]

<?xml version="1.0" encoding="utf-8"?><WorkItemQuery Version="1"><TeamFoundationServer>http://tfs:8080/tfs/DefaultCollection</TeamFoundationServer><TeamProject>Test</TeamProject><Wiql>SELECT [System.Id], [System.Links.LinkType], [System.WorkItemType], [System.Title], [System.AssignedTo], [System.State] FROM WorkItemLinks WHERE ([Source].[System.TeamProject] = @project  AND ( [Source].[System.WorkItemType] = 'Task'  OR  [Source].[System.WorkItemType] = 'UserStory' ) AND  [Source].[System.AssignedTo] = @me) And ([System.Links.LinkType] &lt;&gt; '') And ([Target].[System.WorkItemType] = 'UserStory'  AND  [Target].[System.AssignedTo] &lt;&gt; @me) ORDER BY [System.Id] mode(MayContain)</Wiql></WorkItemQuery>