Visual Studio and TFS work item query tip: combine query clauses into groups
Posted: (EET/GMT+2)
Today's post is a quick tip on how to efficiently query work items in Team Foundation Server (TFS) or Team Foundation Service (aka Visual Studio Online). In Visual Studio, there's a nice user interface for querying work items. But, it might not be immediately obvious on how to work with multiple query clauses.
For instance, let's say you want to create a query that finds both New and Active work items of type Task. You can easily add all these three clauses to the work item query editor, but how can you say that the State of the work item should be New or Active?
Your first attempt might be to enter a State query value like "New OR Active", but this doesn't work. Instead, enter grouping. Grouping allows you to combine query clauses similar to the way you would put parenthesis around an SQL expression. In the query editor, you simply select two or more rows (click the left, gray row marker) and the right-click to group the clauses. The command name is "Group Clauses". A narrow line is shown to visually indicate grouped query clauses.
After grouping, you can change the logical operation from the default AND to OR. Thus, to create a query that finds new or active tasks, your query clauses should be set like this:
Work Item Type = Task | And State = New | Or State = Active
Here, the pipe character indicates grouping of the last two clauses.
Hope this helps!