共用方式為


Example work item queries

Use the following examples to better understand how to query for work items using the query editor.

  • Find items assigned to you using @Me

  • Filter based on date modifications using @Today

  • Filter based on membership in a group or category using In Group

  • Filter based on keywords or phrases

  • Filter based on undefined field values

  • Filter based on reactivations

  • Filter based on different team projects

  • Filter based on linked dependents

Find items assigned to you using @Me

Use = to find current assignments. Use Was Ever to list items based on past assignments.

Was Ever operator to query for past assignment

Filter based on date modifications using @Today

Many dates are added to work item forms automatically. You can find work items that were changed on a given day or during a specific time period. Limiting the scope of a query also helps with performance by only returning those results that fit the date range that you want to include.

You can filter for work items by the date on which they were changed or for a specific time period. If you limit the scope of your query, it can help with performance by only returning those results that fit the date range that you want to include.

  • List items modified today or recently

    Use one of the following clauses to filter items that have been modified recently.

    Editor query filter based on today's date

    Or

    Editor query filter based on recent changes

  • List items modified on a specific date

    Filter based on modification date

    Enter a date in the format accepted by your computer's operating system.

  • List items modified during a specific time period

    Group two clauses to list items that have been modified between a date range.

    Filter based on a date range

Filter based on membership in a group or category using In Group

To filter on items assigned to someone who belongs to a TFS group, use the In Group operator.

Filter based on assignment to a TFS security group

You can use the In Group or Not In Group operators to filter a query based on several values that are members of a group, or that are not members of a group. Examples of groups are TFS groups and work item categories.

Filter based on categories

To filter work items based on the category they belong to, use the In Group operator. For example, the following filter criteria will return all work items that are in the current team project, assigned to the team member, and defined as belonging to the Bug Category.

Query clause to find work items by category

Filter based on keywords or phrases

Use Contains and Contains Words to list items that partially or exactly match the words or phrase that you enter.

Editor for flat list query for filtering key words

Choose Contains or Does Not Contain to search against exact or partial matches of a word or phrase. Choose Contains Words or Does Not Contain Words to search against an exact phrase or to use the wildcard character, *. These operators use the full-text search index.

Team Foundation automatically indexes all long-text fields with a data type of PlainText and HTML and the Title field for full-text search. For restrictions, see Full-text searches for server and collation requirements.

Filter based on undefined field values

You can find work items that have an undefined field value by using the not operator (<>). For example, the following example will find all work items of type Task whose Activity field is blank.

Filter based on blank entries

Filter based on reactivations

To find work items that were closed but then reactivated, you can create a query similar to the one shown. By specifying the Changed Date field, you can focus on reactivations that occurred today, yesterday, or in the last week.

Filter based on reactivation

You can also use the Activated By and Activated Date fields.

Filter based on different team projects

Add this clause to filter items defined in two different team projects.

Filter based on assignment to 2 different projects

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

Filter based on linked dependents

The following example shows a dependent linked query that returns items with dependencies on work managed by other teams and other team projects. Use this query to see all dependent work items that link to active Product Backlog Items or Bugs that have not been removed, closed, or completed. Only those dependent work items that are under a product area other than the Phone Save\Phone Customers are returned.

Work Items and Dependent Links Query

Why this works:

  • Removing the **Team Project = @Project** clause enables all dependent linked work items that match the filter criteria to be listed, no matter which team project they belong to in the collection.

  • Grouping each of two clauses returns all Product Backlog Items on the backlog or in progress, and the second grouped clause returns all Bugs on the backlog or in progress.

  • Grouping the two clauses with the OR operator at the start of the second clause returns work items that match either of the two filter criteria.

  • Choosing the Only return items that have the specified links returns only top-level work items that have dependencies.

  • Choosing Return links of any type returns all linked work items that match the filter criteria for linked work items, in this case, returning all work items that are not under the Phone Saver\Phone Customers area path, and aren't completed or removed.

The following image shows the query results that are returned.

Direct links query results

Q & A

Q: Can I query based on the History field?

A: Yes. For the Field, choose History and for the Operator field, choose Contains Words or Does Not Contain Words.

Enter the full text for the word that you want to search. The History field is indexed for full-text search. If you enter only a partial word, the query will not return work items that contain the full word. For example, if the History field contains the phrase reproducible behavior and you search for repro, the work item will not be found. However, if you search for the complete word reproducible, the work item will be found. You can also search for the string with a wild card, such as repro*.

Also, common words are ignored. The search engine ignores words that are defined as stopwords. For more information, see the following page on the Microsoft Web site: Stopwords and Stoplists.

See Also

Concepts

Query for work items