Mr Giggles
Mr Giggles

Reputation: 2104

How to get the linked items of a work item in Azure DevOps

I am working with the Azure APIs and the VisualStudio.Services.Client.

My goal is to get a list of test Cases associated with a User Story, so far I'm here:

 VssConnection connection = new VssConnection(new Uri("https://{myOrg}.visualstudio.com"),
            new VssBasicCredential("UserName","SuperSecretPassword"));

        WorkItemTrackingHttpClient witClient = connection.GetClient<WorkItemTrackingHttpClient>();

        var ticket =  witClient.GetWorkItemAsync(1234).Result;

Which returns me my user Story.

Question: I want to get at any linked items to this to find my Test Cases, but can't see any way to do this through the UI (so i can call the query) or via the APIs directly.

Any help would be really appreciated!

Upvotes: 2

Views: 3486

Answers (1)

R Pelzer
R Pelzer

Reputation: 1278

Personally I like to use WIQL Queries to retrieve data from Azure DevOps. It is very flexible and it could be used in any situation.

This example below is made for an Azure DevOps Widget. (javascript)

var wiqlQuery = `
SELECT
    [System.Id],
    [System.Title],
    [System.WorkItemType]
FROM workitemLinks
WHERE
    (
        [Source].[System.TeamProject] = @project
        AND [Source].[System.WorkItemType] = 'User Story'
    )
    AND (
        [System.Links.LinkType] = 'System.LinkTypes.Hierarchy-Forward'
    )
    AND (
        [Target].[System.TeamProject] = @project
        AND [Target].[System.WorkItemType] = 'Test Case'
    )
MODE (Recursive)`;

witClient.queryByWiql({ query: wiqlQuery }).then(function(result){
    // Your Code
});

You should keep in mind that the LinkType in important in this query.

Here you can find detailed information about the relation types: Link type reference

Here you can find more information about WIQL queries

Here you can find the detailed information about the Azure DevOps Rest API for WIQL Queries

If you have a query in Azure DevOps and you want to export it as WIQL query, you can use this marketplace extension

Upvotes: 4

Related Questions