Query for work items
Queries help you find work items that you want to review or update.
Use the search box to find work items. Enter the ID or use filters. If you want a flat list of work items, a hierarchical list using a tree query, or a list showing dependencies using a direct links query, use the query editor to choose the query type.
Type the ID in the Search work items box and then choose the search icon.
Using the context menu, you can add filters to list items based on assignment, status, a keyword, or a work item type.
For example, enter A=@Me T=Task to list all tasks assigned to you.
The easiest way to define a query is to start with an existing shared query. The following example shows how to find all closed bugs by modifying the Active Bugs shared query provided with the Agile process template.
Open a shared query. For example, open the Active Bugs or similar flat list query.
Edit the query to find closed bugs and then run the query. Use (Insert new filter line) to insert a clause above the current clause. Use (Remove filter line) to delete a clause.
Save the query to your My Queries folder.
Grouped clauses operate as a single unit separate from the rest of the query, similar to putting parentheses around a mathematical equation or logic expression. The And or Or operator for the first clause in the group applies to the whole group.
In the next example, the first expression returns all work items that are priority 1 and all active bugs of any priority. The second expression returns all active priority 1 work items and all priority 1 bugs, whether they are active or not.
Priority=1 OR (Work Item Type=Bug AND State=Active)
Priority=1 AND (Work Item Type=Bug OR State=Active)
To group one or more clauses, select them and then choose the group clauses icon.
If your query results do not return your expected set of work items, follow these steps:
Make sure that each clause is defined as you intended.
Verify And/Or assignments to each clause. If your results contain more work items than expected, often an Or clause is present instead of an And clause.
Determine if you need to group or change the grouping of the query clauses and the And/Or assignments of each grouped clause.
Add more query clauses to refine your query filter criteria.
Review the options available to specify fields, operators, and values.
Use the tree query () to view a multi-tiered, nested list of work items. For example, you can view all backlog items and their linked tasks.
Expand () or collapse () leaf nodes to focus on different parts of the tree.
Define the filter criteria for both parent and child work items.
To find linked children, select Match top-level work items first. To find linked parents, select Match linked work items first.
Use the direct links query () to track work items that depend on other tracked work, such as tasks, bugs, issues, or features. For example, you can view backlog items that depend on other items being implemented or a bug being fixed.
Use the direct links query to track dependencies your team has that other teams work on, or manage commitments your team has made to other teams. Specify the filter criteria for both top and linked work items, and select the types of links used to filter the dependencies.
Filter your first-tier list of work items by choosing one of these options:
Only return work items that have the specified links: First-tier work items are returned, but only if they have links to work items specified by the linked work items filter criteria.
Return all top level work items: All first-tier work items are returned regardless of the linked work items filter criteria. Second-tier work items that are linked to the first tier are returned if they match the linked work items filter criteria.
Only return work items that do not have the specified links: First-tier work items are returned, but only if they do not have links to work items specified by the linked work items filter criteria.
A: The operators and variables available for selection depend on the field that you select. The four variables are @Project for the project name field, @Me for person-name fields, @Today for date-time fields, and [Any]. See Query fields, operators, values, and variables.
A: There’s no automatic way to do this; you must manually update queries to point to the current sprint. If your team project is based on Scrum or Agile, you’ll find a set of queries under the Current Sprint or Current Iteration folders. For each query to return items defined for the current sprint, you must update the iteration path to the iteration that is current according to the date.
You can change many of your queries by saving them as .wiq files. Open the query in Team Explorer, choose Edit Query, and then choose File, Save As to save each query as a .wiq file. Here is an example of the Work in Progress query that has been updated to support Release 2\Sprint 59.
<?xml version="1.0" encoding="utf-8"?> <WorkItemQuery Version="1"> <Wiql> SELECT [System.Id], [System.WorkItemType], [System.Title], [System.AssignedTo], [System.State], [Microsoft.VSTS.Scheduling.RemainingWork], FROM WorkItems WHERE [System.TeamProject] = @project and [System.IterationPath] under 'FabrikamPrime\Release 2\Sprint 59' and [System.WorkItemType] in group 'Microsoft.TaskCategory' and [System.State] = 'In Progress' ORDER BY [System.AssignedTo], [Microsoft.VSTS.Common.BacklogPriority], [System.Id] </Wiql> </WorkItemQuery>
A: Yes if you’re using Visual Studio Online or if you’ve upgraded to TFS 2013 Update 2, otherwise, no for on-premises deployments.
For Visual Studio Online and with TFS 2013 Update 2, you can choose Tags as a field to filter on. Also, you can open a query from Excel and bulk modify tags assigned to work items. You can also add tags to work items using Visual Studio.
For on-premises deployments, you can show tags as a column in the query results and you can filter a list based on a tag, however, you can’t add tags as a clause to the filter criteria.
A: Set the permissions on the query to Read.
A: To save a query to the Shared Queries folder, get added to the project administrators group.
You can only add shared queries to team favorites, and only if you have team administrator permissions.
A: Yes. From TWA and the Results list for a query, choose the send mail icon. From Team Explorer, open the context menu and choose the Send to Microsoft Outlook. Also, you can only send to TFS user accounts as only these accounts can open the linked work items contained within the query.
If you can’t send email, you need to configure an SMTP server.
To email a list of query results from Team Explorer, you must have Outlook installed on your client computer.
A: Yes. The easiest way to define a hyperlink is to create a query that matches what you want and then copy the URL for the query. The hyperlink uses the work item query language (WIQL), which resembles Transact-SQL, and matches this syntax:
http:// ServerName : Port/ /tfs/CollectionName/TeamProjectName/q.aspx?pname=Project&wiql=WorkItemQueryLanguage
For example, the following hyperlink lists the ID, title, and state of all bugs that have build number 9.0.30304 defined for the AdventureWorksProject project.
http://AdventureWorks:8080/tfs/ /q.aspx?pname=AdventureWorksProject&wiql==SELECT [System.ID], [System.Title], [System.State] FROM WorkItems WHERE [System.TeamProject]='AdventureWorksProject' AND [System.WorkItemType]='Bug' AND [System.FoundIn]='9.0.30304' http://Server1:8091/tfs/web/wi.aspx?id=9035
A: Yes. From the query editor in Team Explorer, use the File menu to save a query as a .wiq file. When you create a team project, the shared queries are created based on .wiq files defined in the process template.
A: The task board only shows tasks linked to backlog items that have been assigned to an iteration. It’s possible to assign tasks to an iteration but not have them linked to a parent backlog item. These items will show up in the created query, but not show up on the task board itself. TFS runs the query and then applies a few background processes before displaying the task board items.