Inside VSTS

Working with Work Item Queries

Mickey shows you the basics of working with Work Item Queries in Team Foundation Server.

No matter what sort of project you're working on, no doubt it includes some sort of "To Do" list that defines what needs to be accomplished. To that end, Team Foundation Server (TFS) includes a work item tracking system to help you track all the work that needs to be done to make your project a success. The work item tracking system is completely customizable, allowing you to customize the information that's tracked, as well as customize how you retrieve and view that information.

You view and manage the work that needs to be done using work item queries. TFS uses a query engine to access work items. You get several queries "out of the box," and you can also use the Team Foundation query builder to create additional queries.

To get started, let's look at what you get out of the box. Figure 1 shows a screenshot of a Team Explorer window.

Under the MyAgileTeamProject Team Project is a Work Items folder. This folder is used to store the queries used to access the work item tracking system. There are two folders under this folder: Team Queries and My Queries. The Team Queries folder contains work item queries that are accessible by the entire team, while the My Queries folder contains queries only you can access. This allows you to create queries other team members can use, while also having queries just for your personal use.

To run a work item query from Team Explorer, simply double-click it. Figure 2 shows the results of running the All Work Items query. The query results are shown in the top window, with the details of the selected work item shown in the bottom.

You can easily modify an existing query by right-clicking on it and selecting View Query. This will open the query editor, as shown in Figure 3. In Figure 3, we're looking at the All Work Items query. As you can see, the query editor allows you to edit the WHERE clause of a work item query. This is very similar to managing the WHERE clause of a SQL statement. You can add multiple steps to your work item query, separated by AND or OR.

You'll notice that in this query, we're querying where Team Project = @Project. The use of these query variables allows you to create queries that are generic and reusable across team projects. In this example, this query states it is to return any work item in the team project where the query is being run. Because the query has been generalized using the query variable, you can move this query to another team project, and it will run in that team project and return all the work items for that team project without any changes being made to the query.

Let's take the All Work Items query and modify it to return only the work items assigned to the person running the query. You can do that by selecting the row that says Click here to add a clause. In the Field column, select Assigned To. In the Operator column, select "=". Finally, in the Value column, select the query variable @Me. Your query should resemble Figure 4.

When you run this query, it will return all the work items in the current team project assigned to the person running the query. As you can see, you can use the query editor to slice and dice information in the work item tracking system to be able to view it in a variety of different ways.

Once you've created a new query, you will want to save it to be able to reuse it. When you go to save your query, you'll be prompted to give your query a name. You'll also need to select the location for your query, as shown in Figure 5.

You can save it as a Team query, making it available to anyone who can access the Team Project. You can save it as a My query, making it available only to yourself. As a third option, you can save the query to a file.

With this article I've shown you the basics of working with work item queries in the TFS work item tracking system. By customizing your work item queries, you can quickly and easily view the work item information in your TFS, the way you want to see it.

About the Author

Mickey Gousset spends his days as a principal consultant for Infront Consulting Group. Gousset is lead author of "Professional Application Lifecycle Management with Visual Studio 2012" (Wrox, 2012) and frequents the speaker circuit singing the praises of ALM and DevOps. He also blogs at ALM Rocks!. Gousset is one of the original Team System/ALM MVPs and has held the award since 2005.

comments powered by Disqus
Upcoming Events

.NET Insight

Sign up for our newsletter.

I agree to this site's Privacy Policy.