Creating queries
Use a query to retrieve a set of work items that meet specific conditions.
About this task
Procedure
- In the Work Items perspective, in the Team Artifacts view, expand the project area.
- Right-click Work Items and select New > Query.
Alternatively, you can create a query in the Work Items view by clicking the Create New Query icon.
- In the query editor, enter a name for the query in the Name field.
Depending on the type of query you want to create, click one of the following links:
- Start from scratch: This query is based on a unique set of
conditions. To create this type of query, after you click Start from scratch,
follow these steps:
- Click the Add Conditions icon.
- In the Condition Selection window, select the attributes to use as query
conditions and click OK. Tip: By default, only the built-in attributes are displayed. To include custom attributes, links, and archived attributes in the list, select the corresponding check box in the lower portion of the window: Show custom, Show links, Include archived. For example, to query on all work items without a Parent link, first select the Show links check box. Then, from the attributes list, select Parent, and click OK. Finally, in Step 2.c., set the attribute condition.
- For each attribute, specify the value or condition that must be met. For example, for the Due Date attribute you can use a specific date or a relative date, such as 15 days from now. As another example, to query on all work items without a Parent, set the Parent attribute condition to do not exist.
- To nest conditions and groups of conditions, click the arrow icon next to the Add Condition icon and select the type of condition to add. For each group, click All must match and select AND or OR. Use AND when all of the conditions you specify must be met for the query to return a work item. Use OR when any one of the conditions must be met.
- To specify input variables for an attribute condition, in the upper-right corner of the attribute condition area, click the Enable Input of Condition Values when Query is Run icon. When you run the query, the Assign Parameter Values wizard opens. In the wizard, select the values for every input variable and run the query.
- Simple Query: This query uses the Status, Category, Owner, and
optional text conditions. To create this type of query, after you click Simple
Query, follow these steps:
- Select one or more values for the Status, Category, and Owner attributes.
- Enter a text string. The query searches fields of the work items for matching occurrences of the text string. Queries for string-based fields, such as Summary and Description, are not case-sensitive. Add and remove conditions as necessary.
- Full Text Query: This query searches all fields of work items for a
text string. To create this type of query, after you click Full Text Query,
follow these steps:
- Enter the text string.
- Add and remove conditions as necessary. Queries for string-based fields, such as Summary and Description, are not case-sensitive.
- Start from scratch: This query is based on a unique set of
conditions. To create this type of query, after you click Start from scratch,
follow these steps:
- Click the Details tab. Enter a description of the query so that other users can understand which work items the query returns without reading the Conditions tab.
- By default, new queries are private. To share a query with members of a team, click
Share > Team or Project Area and select a team. To share a query with a
specific user, click Share > User and select the user. Tip: If you change a shared query, the changes apply to the other users with whom you share the query. If you delete a shared query, that query is no longer available to users with whom you shared the query.
- Click the Column Display tab. In the Columns section, double-click
each attribute that you want to display as a column heading in the query results grid. Scroll to the
Sorting area. Double-click the attribute to use for sorting the work items in the query results
grid. In the Selected sort columns table, you can set the sort direction to Ascending or Descending.
The first attribute that you select is the primary sorting attribute. You can specify additional sorting attributes.Note: You are able to create a query that includes empty fields: for example, text fields without content can be included in your query.
- To save the query, click Save.
Another way to create a query is to edit an existing query. When you finish editing, click Save Copy and provide a different name for the query.
- To run the query, click the Run icon.
- To create a feed for this query, click the Create RSS Subscription for this Query icon. When any work items that are selected by this query change, you will receive notifications in the Team Dashboard view.