1

I try to query the work item data to get a flat list of PBIs that belong to a given Epic with a parent relation ship Epic > Feature > PBI. Wiql seems to be limited in this regard, I can't find a "join" clause.

In SQL, I'd do it somehow like this (pseudo script):

select P.*
from Epic E
    inner join Feature F on E.Id = F.EpicId
    inner join Pbi P on F.Id = P.FeatureId
where E.Title = 'Project 1'

The background is to create a shared query (or even using the API) and build a dashboard chart to see the number and states of the PBIs in a given Epic.

Any idea how I can achieve this kind of query?

infero
  • 843
  • 2
  • 11
  • 22

1 Answers1

0

We can list all the child items in an Epic instead of all PBIs, please use WIQL below to get all child item from a specific parent work item(ID):

SELECT
    [System.Id],
    [System.WorkItemType],
    [System.Title],
    [System.AssignedTo],
    [System.State],
    [System.Tags]
FROM workitemLinks
WHERE
    (
        [Source].[System.TeamProject] = @project
        AND [Source].[System.WorkItemType] = 'Epic'
        AND [Source].[System.State] <> ''
        AND [Source].[System.Id] = {Epic ID}
    )
    AND (
        [System.Links.LinkType] = 'System.LinkTypes.Hierarchy-Forward'
    )
    AND (
        [Target].[System.TeamProject] = @project
        AND [Target].[System.WorkItemType] = 'Product Backlog Item'
    )
ORDER BY [System.Id]
MODE (Recursive)

enter image description here

As a workaround, when we add child item(PBI) to an epic, we can add a same tag and get the result via query tag, then we can create a dashboard chart to see the number and states of the PBIs in a given Epic.

enter image description here

Vito Liu
  • 7,525
  • 1
  • 8
  • 17
  • thx for your answer. First query/way is what I know but can't use, because I only want the PBIs, second query/way using the tags is what I wanted to avoid, because forgetting to set a tag is very possible – infero Jul 30 '20 at 14:44
  • Maybe we can export the query to Excel and then filter it? I cannot found another way to list only PBI, – Vito Liu Aug 03 '20 at 10:17