0

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.

scigor
  • 1,603
  • 5
  • 24
  • 38

1 Answers1

1

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>
Community
  • 1
  • 1
MikeR
  • 3,045
  • 25
  • 32
  • this isn't exactly what i am looking for, maybe a wiql query would be better – scigor Jan 30 '14 at 10:24
  • Do you want to run WIQL in code? Because I don't know any other place where to use it. I added a 3rd query, which might could solve your issue. – MikeR Jan 30 '14 at 10:35
  • Actually if you save a query to file, you will notice that it basicaly contains wiql code between the tags. So you can create any Wiql query and run it, so you are not restricted by the vs query editor. – scigor Jan 30 '14 at 11:40
  • added WIQL for 3rd query – MikeR Jan 30 '14 at 11:50
  • I really appreciate the effort (upvote), but as you understand, your solution isn't exactly what i am looking for. – scigor Jan 30 '14 at 12:30
  • I don't get the difference to what you exactly looking for. From your 3 descriptions the result for me is: Show UserStories that are assigned to me (doesn't matter if linked Tasks are assigned or not) and Tasks that are assigned to me and linked to a UserStory that is not assigned to me. – MikeR Jan 30 '14 at 12:48
  • The thing is, that it was an example of what i actually trying to achieve. There are more levels in the actual case. That's why i wanted a query to get the topmost element. Your answer is basically a workaround to what i was trying to achieve. But you are right, according to the wording of my question your answer is correct. I will mark it as solved. – scigor Feb 03 '14 at 08:05
  • if i saved a query as my fav, will this my fav query saved as local file for me to customize it through wiql? – Kelmen Nov 11 '15 at 03:06