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 by ID or with simple filters. Use the query editor to refine the filter criteria to return a flat list of work items, a hierarchical list using a tree query, or a list showing dependencies using a direct links query.
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.
Assess 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: No. 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.
Open the context menu and choose the star next to a work item query to add to My favorites or Team favorites. 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.