Query work items by link or attachment count
TFS 2017 | TFS 2015 | TFS 2013
You can link work items to track related work and dependencies and attach files to share information with your team. You can then list work items based on one or more of the following fields:
- Attachment File Count
- External Link count
- Hyperlink Count
- Link Comment
- Related Link Count
For descriptions of each of these fields, see the table provided later in this article.
Supported operators and macros
Query clauses that specify an integer field can use the operators listed below.
= , <> , > , < , >= , <= ,
=[Field], <>[Field], >[Field], <[Field], >=[Field], <=[Field],
In, Not In,
Was Ever
Link or attachment count queries
You can filter for work items by the link type, link count, or attachment count.
Filter for
Include these query clauses
Items with attachments
Attached File Count >= 1
Items with two or more hyperlinks
Hyperlink Count >= 2
Items containing external links, links to objects other than work items
External Link Count >= 1
Items that contain between three and seven related links
Related Link Count >= 3
And
Related Link Count <= 7
List hierarchical items in a tree view
Add a query and select Tree of work items to begin your query. You should see something similar to the following examples:
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>Test Plans page.
From there, you can add query clauses or change the filter options for linked work items.
Filter for
Include these query clauses
View only child items of work item 645
Add to Filters for top-level work items:
ID = 645
Tasks or bugs
Add to Filters for linked work items:
Work Item Type In Task,Bug
Items assigned to my team (Web)
Add to both top and bottom filters:
Assigned to In Group [Fabrikam Fiber]\Web
Parent items of tasks assigned to me
Change Filter options to Match linked work items first
Add to Filters for linked work items:
Assigned To = @Me
List items based on linked dependents
The following example shows a dependent linked query that returns items with dependencies on work managed by other teams and projects.
The following query finds work items in all projects that are linked to work items under the Fabrikam area path and project using Predecessor and Successor link types.
Why this works:
Checking the Query across projects checkbox enables all dependent linked work items that match the filter criteria to be listed, no matter which project they belong to.
Specifying the Area Path Under Fabrikam clause indicates to find only work items that are linked to work items defined under the Fabrikam project.
Specifying Only return items that have matching links, and Return selected link types causes the query to return only work items that are linked based on the Predecessor and Successor link types.
List orphan user stories
If you typically organize your user stories under features, you can quickly find user stories that are orphan by opening the product backlog, enable Parents On view option, and scroll down to the section that lists Unparented Stories (Agile) or Unparented Backlog items (Scrum).
Or, you can find unparented backlog items using a Work items and direct links query. For example, the following query lists active user stories for the Azure DevOps team that don't have a Parent link.
Link, attachment count, and comment fields
The following table describes fields associated with links and attachments. Most of these fields don't appear within the work item form, but are tracked for all work item types.
Field name
Description
Work item type
Attachment File Count
The number of files attached to the work item and stored in the work item tracking database.
Reference Name=System.AttachedFileCount, Data type=Integer
Note
For Azure Boards (cloud service), you can add up to 100 attachments to a work item. Attempts to add more result in an error message upon saving the work item.
All
Comment Count
The number of comments added to the Discussion section of the work item.
Reference Name=System.CommentCount, Data type=Integer
Note
Available for TFS 2017 with the new work item form which supports the Discussion section and later versions.
All
The number of links from the work item to artifacts that are not work items. such as pull requests, commits, changesets, or other link types.
Reference Name=System.ExternalLinkCount, Data type=Integer
All
The number of hyperlinks that are defined for the work item.
Reference Name=System.HyperLinkCount, Data type=Integer
All
Link Comment
Contains comments from the team member who created the link. You can configure this field to appear as a column in a list of links on a work item form. (Not supported in query editor.)
Reference Name=System.Links.Comment, Data type=PlainText
All
Link Description
Contains the work item type, ID, and title of the work item that is the target of the link. You can configure this field to appear as a column in a list of links on a work item form. (Not supported in query editor.)
Reference Name=System.Links.Description, Data type=PlainText
All
When included as a column option in a backlog or query results list, the Title of the parent work item is displayed. Internally, the system stores the ID of the work item within an Integer field.
Note
The Parent field is available from Azure DevOps Server 2020 and later versions. You can't specify this field within a query clause. Reference Name=System.Parent, Data type=Integer
All
The number of links defined for a work item which use a work link type, such as Parent-Child, Predecessor-Successor, and Related. For a full list, see Link type reference.
Reference Name=System.RelatedLinkCount, Data type=Integer
All
Available for Azure DevOps Services only. The number of links from a work item to work items defined in another organization. Organizations must be managed by the same Azure Active Directory. Supported link types include Consumes From, Produced For, and Remote Related. To learn more, see Add link to work items, Link to a remote work item.
Reference Name=System.RemoteLinkCount, Data type=Integer
All
Related articles
- Add a link to multiple work items
- Linking, traceability, and managing dependencies
- Track dependencies using Delivery Plans
- Query quick reference
- Query editor
- Query fields, operators, and macros
- Add work items
- Work item field index
Visualize related work and other objects
You can view related work items and object within a work item form by installing the Work item visualization extension available from the Visual Studio Marketplace, Azure DevOps tab.
Add custom link types or customize the links controls
To add link types, see Manage link types [witadmin].
All tabs that support creating links between work items are implemented by using the LinksControl element on the work item form. This element controls filtering and restricting the types of work items to which you can link, the types of links that you can create, and whether you can link to work items in another project. To customize the link controls and restrictions, you modify the definition of the LinksControlOptions
for a work item type, see LinksControlOptions XML elements.
Default data fields in lists of links
You can add or remove columns from the list of links, and you can customize the default columns and the column order. For more information, see LinksControlOptions XML elements.