How to list all child items of specific product backlog item - wiql

I want to list all of the child items that belongs to one specific product backlog item. For example; the algorithm below lists all the parents that belong to the child. I want to do its vice versa which is listing all the children for a parent.
SELECT
[System.Id],
[System.Title],
[System.AssignedTo],
[System.State]
FROM workitemLinks
WHERE ([System.Links.LinkType] = 'System.LinkTypes.Hierarchy-Forward')
AND ([Target].[System.Id] = 1111)
ORDER BY [System.Id]
MODE (Recursive, ReturnMatchingChildren)
I have done some research on Google but I always found the version of "All parents for child item" query. Since I have never used WIQL before and it's one time need, I struggled a bit. I am aware that I can do this from the queries part with the new update of Microsoft. But my company uses the old version of 2020 so the new parent filtering options are unavailable for me.

Related

Azure DevOps API Combine OData Queries?

I'm using the following 3 queries in order to get a list of Task/User Story/Feature relationship in a given Sprint (Iteration)
I'm no Odata expert, but it would seem in some way I could combine the 3 queries into 1 to retrieve Task, Parent (User Story) Parent (Feature) and associated Assigned Usernames.
Is this possible or could this be done another way?
Get Task and parent User Stories
https://analytics.dev.azure.com/{org}/{projectName}/_odata/v3.0-preview/WorkItems?$select=AssignedToUserSK,WorkItemId,Title,State,WorkItemType,ParentWorkItemId,RemainingWork,CompletedWork,OriginalEstimate&$expand=Parent($select=WorkItemId,Title,State,WorkItemType,ParentWorkItemId,StoryPoints,StackRank)&$filter=Iteration/IterationPath eq '{sprint}' and WorkItemType eq 'Task'";
Get parent Feature of User Stories (from above)
https://analytics.dev.azure.com/{org}/{projectName}/_odata/v3.0-preview/WorkItems?$select=WorkItemId, Title, State, &$filter=WorkItemId in ({parentStoryFeatureIdsStr})
Get Work Item and Assigned User Name
https://analytics.dev.azure.com/{org}/{projectName}/_odata/v3.0-preview/WorkItems?$select=WorkItemId,&$expand=AssignedTo($select=UserName)&$filter=Iteration/IterationPath eq '{sprint}' and WorkItemType eq 'Task'"
You can have a try using $expand on Descendants to query Feature and its decendants work items(User Story and Task). See below example:
https://analytics.dev.azure.com/{org}/{projectName}/_odata/v3.0-preview/WorkItems?$filter=WorkItemType eq 'Feature'&$expand=Descendants($filter=Iteration/IterationPath eq '{sprint}'; $select=AssignedToUserSK,WorkItemId,Title,State,WorkItemType,ParentWorkItemId,RemainingWork,CompletedWork,OriginalEstimate;$expand=AssignedTo($select=UserName))
Using $expand on Descendants will return all the children User Stories and grandchildren Tasks of the Feature work items.
If you have to use $expand on Parent to query from Tasks to Parent User Stories and then to Parent Feature. I am afraid it is impossible to combine the 3 queries into 1. For the maximum depth allowed for $expand on Parent is 1 .
However, You can combine the 3 queries into 2 like below(combine the 3rd query into the 1st query):
https://analytics.dev.azure.com/{org}/{projectName}/_odata/v3.0-preview/WorkItems?$select=AssignedToUserSK,WorkItemId,Title,State,WorkItemType,ParentWorkItemId,RemainingWork,CompletedWork,OriginalEstimate&$expand=Parent($select=WorkItemId,Title,State,WorkItemType,ParentWorkItemId,StoryPoints,StackRank),AssignedTo($select=UserName)&$filter=Iteration/IterationPath eq '{sprint}' and WorkItemType eq 'Task'"

get all my features + stories from all AND all my stories connected to other features

This question is about Azure Boards and querying Work Items.
My use case is:
I have different projects set up
epics and features are maintained in a global planning project
stories life in the product projects
the final setup will be quite huge that’s why this separation has been introduced we will have to ensure the system is maintainable (permissions etc.)
association from the planning project to others works with area paths which are set up in the planning project and represent the structure of all projects
some features need support from other projects so I setup one parent-child-linked story in the other project
I want now a single hop query which shows me all features and the child stories
the rules should be:
show all the features I have associated to my project plus all the stories connected to them, this includes stories which are in other projects and teams
show also all my stories, including those which I’m doing for other features in other projects
For more visual people an example diagram below. In queries which are saved as shared queries in all 3 projects there should be this result:
Project "Product 1" sees both product features and its stories as one is the own feature and the other contains a story which is linked to the own project / team
Project "Product 2" has the same vice versa
The Project Platform sees also both of these product features as it has a story of each plus it has a third feature which is not in the queries of the products as it only contains Platform stuff
I want to see that because the dependencies are important and each project team should see, where they have dependencies to other products and where they have to deliver or are waiting for things.
(example of the query one below "give me all stories belonging to my features")
The only way I found so far is to have two separate queries which apply the two mentioned rules and combine them. A UNION (without duplicates, so no UNION ALL) would do the trick in one go. Here are my current two test queries.
/** give me all stories belonging to my features **/
SELECT
[System.Id],
[System.WorkItemType],
[System.Title],
[System.AssignedTo],
[System.State],
[System.Tags]
FROM workitemLinks
WHERE
(
[Source].[System.WorkItemType] = 'Feature'
AND [Source].[System.AreaPath] UNDER 'PI-Planning\Plattform'
)
AND (
[System.Links.LinkType] = 'System.LinkTypes.Hierarchy-Forward'
)
AND (
[Target].[System.WorkItemType] <> ''
)
ORDER BY [System.Id]
MODE (MayContain)
/** give me all features belonging to my stories **/
SELECT
[System.Id],
[System.WorkItemType],
[System.Title],
[System.AssignedTo],
[System.State],
[System.Tags]
FROM workitemLinks
WHERE
(
[Source].[System.WorkItemType] = 'Feature'
)
AND (
[System.Links.LinkType] = 'System.LinkTypes.Hierarchy-Forward'
)
AND (
[Target].[System.WorkItemType] <> ''
AND [Target].[System.AreaPath] = 'Plattform'
)
ORDER BY [System.Id]
MODE (MustContain)
I also opened a feature request at Microsoft but until someone replies there, we get old and grey ...
WIQL: allow UNION of queries

How to disallow closing a parent work item when it has non-closed child work items in Azure Boards?

I would like to avert the "invalid" state change up front by notifying the user or even preventing the change via a Rule. However, I do not see any rule capability's when conditions that are based on the state of linked work items.
It would be nice if it would prompt the user if they want to change the state of all children, but I'm pretty sure that would be a feature request. (Extension?)
As of now, I have figured out how to write a query to identify these occurrences after the fact.
SELECT
[System.Id],
[System.WorkItemType],
[System.Title],
[System.State],
[System.AssignedTo],
[Microsoft.VSTS.Common.ResolvedBy],
[Microsoft.VSTS.Common.ClosedBy],
[Microsoft.VSTS.Common.ResolvedDate],
[Microsoft.VSTS.Common.ClosedDate],
[System.AreaPath],
[System.IterationPath]
FROM workitemLinks
WHERE
(
[Source].[System.TeamProject] = #project
AND [Source].[System.State] = 'Closed'
)
AND (
[System.Links.LinkType] = 'System.LinkTypes.Hierarchy-Forward'
)
AND (
[Target].[System.TeamProject] = #project
AND NOT [Target].[System.State] IN ('Closed', 'Removed')
)
ORDER BY [System.Id]
MODE (MustContain)
I'm afraid there is no such way to meet your needs.
We cannot judge whether to close the parent work item based on the status of the child work item.
On the other hand, the state field cannot be used in the rule now.
The state of work items are independent of all other work items, including linked work items.
Now this requirement can only be achieved by manually monitoring the status of the work item.
Since you can create query to get parent and child work items, you could monitor them via the query.
However, this feature is very meaningful. I posted a similar Suggestion Ticket in the UserVoice forum before. You can vote and add comments to express your suggestions.

How to get a list from all work items from a specific board in TFS API without ID?

I'm using TFS and I would like to get all work items from a specific board. This is how I'm getting the board atm: https://myTFSLink.com/tfs/TPC/ProjectName/MY-BOARD-NAME/_apis/work/boards?api-version=5.1
But nothing about stories/workItems are present in this API request. I know I can get all workItemsRevisions using
GET https://dev.azure.com/{organization}/{project}/_apis/wit/reporting/workitemrevisions?api-version=5.0
but I don't know how I can target this to a specific board :(
I also know that I can get multiple workItems by ID with
GET https://dev.azure.com/fabrikam/_apis/wit/workitems?ids=297,299,300&$expand=all&api-version=5.1
but the ideal would be get all workItems from a specific board as I said in the beginning. Is there any way to do it?
A specific board is corresponding to a Team/Area Path, so you can try to query the work items By Wiql. For example,
POST https://dev.azure.com/{organization}/{project}/{team}/_apis/wit/wiql?api-version=5.1
Request Body:
{
"query": "Select [System.Id], [System.Title], [System.State] From WorkItems Where [System.WorkItemType] = 'PRODUCT BACKLOG ITEM' AND [Area Path] = 'TestCase\\Team1' order by [System.CreatedDate] desc"
}

Using a Group By and Count statement in WIQL (Azure Dev Ops)

I want to make a WIQL query to count the workitems from the type 'Bug', grouped by the title and the software version fields. But, there is no group by function in WIQL. Does anyone have an alternative to make this work in WIQL?
SELECT
[System.Title],
[System.State],
count(*)
FROM workitems
WHERE
[System.WorkItemType] = 'Bug'
AND [System.State] <> ''
GROUP BY [System.Title], [Custom.ToolSoftwareVersion]
The queries are used to create dashboards and overviews, ect.
Does anyone have an alternative to make this work in WIQL?
Based on my experience, the short answer is no.
As you mentioned, GROUP BY and COUNT are not supported currently. More information on the WIQL syntax is available in this document.
Azure DevOps also supports using the WIQL API to query the result. My workaround is that you could query the result as a list, then you could GROUP BY and COUNT the results with our customized code.
POST https://dev.azure.com/{organization}/{project}/{team}/_apis/wit/wiql?api-version=5.0-preview.2
By the way, you also could give your feedback to the Azure DevOps team.
An alternative approach is to use a "Chart for Work Items" widget that provides a Pivot Table view. You can choose aggregation types such as COUNT, SUM.
This operates similarly to Pivot Tables in Excel with numbers in the output rather than a chart.
Choose Chart Type:
Choose row and column axes
The result is presented as a table with "group by" / count style