Jesper Lund Stocholm
Jesper Lund Stocholm

Reputation: 2013

VSTS: Query all work items for a given Feature

Is it possible to extract a list all work items and bugs for a given feature in VSTS? I do not see a "Parent ID" or similar that I can search after.

The thing is that I would like to use the query for a "Work item" tile on the dash-board displaying the number of bugs and work items for this specific feature.

The work-around is to annotate all bugs and work items with a tag and then filter on that, but it is a manual step that I would like to avoid.

Thanks :-)

Upvotes: 0

Views: 5353

Answers (2)

starian chen-MSFT
starian chen-MSFT

Reputation: 33698

You can custom dashboard widget (VSTS extension) with REST API to display the result what you want.

The simple sample (show child workitems count of query):

<!DOCTYPE html>
<html>
<head>
    <title>Custom widget</title>
    <meta charset="utf-8" />
    <script src="node_modules/vss-web-extension-sdk/lib/VSS.SDK.js"></script>
    <script type="text/javascript">
        VSS.init({
            explicitNotifyLoaded: true,
            usePlatformStyles:true
        });
        VSS.require(["TFS/Dashboards/WidgetHelpers", "TFS/TestManagement/RestClient", "TFS/WorkItemTracking/RestClient", "TFS/Build/RestClient"], function (WidgetHelpers, TFS_Test_WebApi, TFS_Work_WebApi,TFS_Build_Client) {
            WidgetHelpers.IncludeWidgetStyles();
            VSS.register("WidgetStarain", function () {

                var projectId = VSS.getWebContext().project.id;
                var runQuery = function (widgetSettings) {
                    TFS_Work_WebApi.getClient().queryById('7633dab2-89e4-4da9-b03d-a16728ab71c5', projectId)
                    .then(function (workitemResult) {
                        var ss = "gg";

                        ss = workitemResult.workItemRelations[0].target.url;
                       var resultCount = workitemResult.workItemRelations.length;
                       $('div.childWorkItemCount').text(resultCount-1);
                    })
                }

                return {
                    load: function (widgetSettings) {
                        var $title = $('h2.title');
                        $title.text('starain widget custom');
                        runQuery(widgetSettings);
                        return WidgetHelpers.WidgetStatusHelper.Success();
                    }
                }
            });
            VSS.notifyLoadSucceeded();
        });
    </script>
</head>
<body>
    <div class="widget">
        <h2 class="title">widgets sample</h2>
        <div class="childWorkItemCount">-1</div>
    </div>
</body>
</html>

Part code in .Json file:

{
      "id": "WidgetStarain",
      "type": "ms.vss-dashboards-web.widget",
      "targets": [ "ms.vss-dashboards-web.widget-catalog" ],
      "properties": {
        "name": "widget starain",
        "description": "custom widget",
        "catelogIconUrl": "Images/iconProperty.png",
        "previewImageUrl": "Images/iconProperty.png",
        "uri": "WidgetStarain.html",
        "supportedSizes": [
          {
            "rowSpan": 1,
            "columnSpan": 2
          }
        ],
        "supportedScopes": [ "project_team" ]
      }
    }

Upvotes: 0

Giulio Vian
Giulio Vian

Reputation: 8343

Two question in one post.

First the query, yes it is very easy to pull all "descendant" work items using a hierarchical query.

enter image description here

As per the widget, you must use the Query Tile; the Chart for Work Items says Hierarchical queries are not supported.

enter image description here

Note that the root ancestor is included in the count.

Upvotes: 2

Related Questions