Define a work item query in Azure Boards

Azure DevOps Services | Azure DevOps Server 2022 - Azure DevOps Server 2019 | TFS 2018

Visual Studio 2019 | Visual Studio 2022

Work item queries generate lists of work items based on the filter criteria you provide. You can then save and share these managed queries with others. In contrast, semantic searches list work items, but can't be saved or shared.

Create queries from the web portal or from a supported client, such as Visual Studio Team Explorer and Team Explorer Everywhere. You can also define and import a work item query using WIQL syntax and a .wiq file. To support bulk updates or additions, import or export queries using Excel or .csv files.

Create queries from the web portal or from a supported client, such as Visual Studio Team Explorer and Team Explorer Everywhere. You can also define and import a work item query using WIQL syntax and a .wiq file. To support bulk updates or additions, import or export queries using Excel.

Query Editor, web browser.

If you find that your queries take too long to return results, review the Guidance to create high-performing queries.

In this article you'll learn:

  • How to add or create a query
  • How to query across projects
  • How to group and ungroup query clauses
  • How to create a tree of work items or a direct-links query

For quick access to all query tasks, supported operators—such as, Contains, In, In Group, and <>(not operator) — based on field data type, and query examples, see Query quick reference.

Choose a query filter

From the Query Editor, exercise the following filter functions. Choose the filter to jump to an article with sample queries. Along with the query filters, you can interactively apply filters to query results.

Note

Managed queries don't support proximity searches, however semantic searches do. In addition, semantic searches supports both * and ? as wildcard characters and you can use more than one wildcard character to match more than one character. To learn more, see Functional work item search.


Filter features

Macros



Along with the filters you use from the Query Editor, you can interactively filter a query result using the Filter function. To learn how, see Interactively filter backlogs, boards, queries, and plans.

Prerequisites

  • By default, all project members and users with Stakeholder access can view and run all shared queries. You can change the permissions set for a shared query folder or shared query. For details, see Set query permissions.
  • To add and save a query under Shared queries, you must be granted Basic access or higher. Also, you must have your Contribute permission set to Allow for the folder you want to add the query to. By default, the Contributors group doesn't have this permission.

Note

Users with Stakeholder access for a public project have full access to query features just like users with Basic access. For details, see Stakeholder access quick reference.

  • By default, all project members and users with Stakeholder access can view and run all shared queries. You can change the permissions set for a shared query folder or shared query. For details, see Set query permissions.
  • To add and save a query under Shared queries, you must be granted Basic access or higher. Also, you must have your Contribute permission set to Allow for the folder you want to add the query to. By default, the Contributors group doesn't have this permission.

Open Queries

From your web browser, (1) check that you have selected the right project, (2) choose Boards>Queries, and then (3) choose All.

Open Boards>Queries, vertical nav

If it is your first time opening Queries, the page opens to Favorites. This page lists those queries that you have indicated are a favorite. Otherwise, you can choose All to view all queries you've defined and shared queries defined for the project.

Tip

Queries you or your team have chosen as favorites show up on the Favorites page. Favorite queries along with other objects also appear on your Project page. To learn more, see Set personal or team favorites.

From your web browser, open Boards>Queries.

From your web browser, open Boards>Queries

Define a flat-list query

You can start a fresh, new query from the Queries tab in the web portal or the Work Items tab in Team Explorer.

Screenshot to Add new query, new experience.

The Query Editor displays with the following default settings: Flat list of work items, Work Item Type=[Any], and State=[Any].

Screenshot of Query Editor with flat list of work items selected.

You can modify the Values and add or remove clauses. Or, change the Type of query to Work items and direct links or to a Tree of work items.

Screenshot to Queries page, Choose New query from the drop down menu.

The Query Editor displays with the following default settings: Flat list of work items, Team Project=@Project (the current project), Work Item Type=[Any], and State=[Any].

Screenshot of Query Editor with flat list of work items selected, TFS 2018 and earlier versions.

You can modify the Values and add or remove clauses. Or, change the Type of query to Work items and direct links or to a Tree of work items.

Query across or within projects

New queries scope to the current project by default. However, you can create queries to find work items defined within the organization or project collection. All queries that you save, however, are saved under a specific project.

To list work items defined in two or more projects, checkmark Query across projects. For example, the following query finds all features created in all projects within the last 30 days.

Screenshot of Query Editor with Query across projects checked.

With the Query across projects checked, you can add the Team Project field to filter to a select number of projects.

Screenshot of Query Editor with Team Project and other fields added to filter.

Note

Separate multiple project names with the list separator that corresponds to the regional settings defined for your client computer, for example, a comma (,).

The Team Project field is available only after you check Query across projects. Further, when Query across projects is unchecked, only those fields from those work item types, as defined in the current project, appear in the Field drop-down menu. When Query across projects is checked, all fields from all work item types defined in all projects in the collection appear in the Field drop-down menu.

Define a clause

You create a query by defining one or more clauses. Each clause defines a filter criteria for a single field.

Sample query clause

And/Or Field Operator Value
And Assigned To = @Me

For a list of available operators based on the field data type, see Query index quick reference.

All clauses you add are added as an And statement. Choose Or to change the grouping. You group clauses to ensure that the clause statements are run in the sequence required.

Choose Add new clause to add another clause at the end of the query, and then choose the Field, Operator, and Value for that clause.

Screenshot of Query Editor showing how to add a clause.

For example, search for all work items assigned to you by specifying the Assigned To field, the equals (=) operator, and the @Me macro, which represents your user identity.

Tip

To view the WIQL syntax for a query, and how parenthesis are used to group clauses, install the Marketplace Wiql Editor. This extension supports viewing the WIQL syntax and exporting it to a WIQL file for use in REST API calls. To learn more, see Syntax for the Work Item Query Language (WIQL).

Checklist for how to define a query clause

  1. In the first empty row, under the Field column heading, choose the down arrow to display the list of available fields, and choose an item in the list.

    For more information, see Query Fields and Values.

  2. In the same row, under the Operator column heading, choose the down arrow to display the list of available operators, and choose an item in the list.

    For more information, see Operators.

  3. In the same row, under the Value column heading, either type a value, or choose the down arrow, and choose an item in the list.

    For more information about how to use a macro or variable to specify the current project, user, date, or other selection, see Variables.

  4. To add a clause, choose Add new clause.

    You can add a clause to the end of the query, or perform the following tasks with the corresponding icons:

    • Insert new filter line
    • Remove this filter line
    • Group selected clauses
    • Ungroup clauses

Use a work item tree to view hierarchies

Use the Tree of Work Items query to view a multi-tiered, nested list of work items. For example, you can view all backlog items and their linked tasks. To focus on different parts of the tree, choose Expand all or Collapse all.

Note

You can't construct a query that shows a hierarchical view of Test Plans, Test Suites, and Test Cases. These items aren't linked together using parent-child link types. However, you can create a direct links query that lists test-related work items. Also, you can, view the hierarchy through the Test Plans page.

Screenshot of Query Results List showing a Tree Query.

Screenshot of Query Results List showing a Tree Query, TFS 2018 view.

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.

Screenshot of Query Editor view of Tree of work items.

Use the Work items and 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 across teams. The query also helps you manage commitments your team makes. Choose the filter criteria for the top and linked work items. And, select the types of links to filter the dependencies.

Screenshot of Direct Links Query Results.

Screenshot of Query Editor, Direct Links Query.

Filter your first-tier list of work items by choosing one of these options:

  • Only return items that have matching links: First-tier work items return, but only if they have links to work items specified by the linked work items filter criteria.

  • Return all top level items: All first-tier work items return despite the linked work items filter criteria. Second-tier work items that are linked to the first tier return if they match the linked work items filter criteria.

  • Only return items that do not have matching links: First-tier work items are returned, but only if they don't have links to work items specified by the linked work items filter criteria.

To learn more about each link type, see Linking, traceability, and managing dependencies.

And/Or logical expression

You specify And or Or to create logical expressions of your query clauses. Specify And to find work items that meet the criteria in both the current clause and the previous clause. Specify Or to find work items that meet the criterion in either the current clause or the previous clause.

Add one new clause for each work item field to refine your search criteria. Add clauses to return only the set of work items you want. If you don't receive the results you expect from your query, refine it. You can add, remove, group, or ungroup query clauses to improve your query results.

Group query clauses to operate as a single unit separate from the rest of the query. Grouping clauses is similar to putting parentheses around an expression in a mathematical equation or logic statement. When you group clauses, the AND or OR for the first clause in the group applies to the whole group.

Group clauses

Grouped clauses operate as a single unit separate from the rest of the query. Grouping clauses is 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.

As the following examples show, the grouped clauses are translated to the corresponding logical expression.

Tip

To view the WIQL syntax for a query, install the WIQL query editor extension which will allow you to see the WIQL version of any Query UI entry. This extension allows you to see just how AND/OR grouped clauses are treated.

Query Grouped clauses Logical expression
1 Screenshot showing a group clause query. Filters are set up for the Work item type field and either the State field or the Assigned to field. Screenshot of a logical expression. An AND operator groups the Work item type, State, and Assigned to fields. An OR operator groups the State and Assigned to fields.
2 Screenshot showing a group clause query, with filters for both the Work item type field and one of either the State field or the Assigned to field. Screenshot of a logical expression. An AND operator groups the Work item type with the State or Assigned to fields, which are grouped by an OR operator.
3 Screenshot showing a group clause query. Filters are set up for either the Work item type field or both the State field and the Assigned to field. Screenshot of a logical expression. An OR operator links the Work item type to both the State and the Assigned to fields, which are linked by an AND operator.

These queries return work items that are type Bug and meet the following logical expressions:

  • Query 1: AND State=Active OR Assigned to @Me
  • Query 2: AND (State=Active OR Assigned to @Me)
  • Query 3: OR (State=Active AND Assigned to @Me)

To group one or more clauses, select them and then choose the group clauses icon.

Screenshot of Web portal, Query Editor, Group Selected Query Clauses.

You can also group several grouped clauses. Check the boxes of each clause that's already been grouped. Then, choose the group clauses icon.

Screenshot of Web portal, Query Editor, Group multiple query clauses.

If your query results don't return expected results, 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.

Ungroup a clause

To ungroup a clause, choose the ungroup clauses icon for the grouped clause.

View query results in a dashboard

The following two widgets display query results. You can open work items directly from these widgets.

  • Work assigned to me: Lists all proposed or active work items assigned to the signed-in user. Lists the ID, State, and Title fields.
  • Query results widget: Displays the results of a flat, tree, or direct-links query. You can configure the fields displayed through the widget, resize the column fields, and expand and collapse tree and direct-links query.

To learn more about adding widgets to a dashboard, see Add widgets to a dashboard.

View query results widget with Parent titles

You can view the results of a query with the Parent title displayed. To do so, perform these steps:

  1. Create the query that filters the work items of interest. The query can be a flat-list, tree, or direct-links query.
  2. Add the Parent field as a column.
  3. Save the query as a Shared query or Team favorite.
  4. Add the Query results widget to your dashboard and configure the query. Make sure the Parent field is set to display.

The following image illustrates a query results widget that displays the Parent field.

Screenshot of query results widget showing a Parent column field.

That's the basics about defining queries. For an index of query examples, see Query quick reference.