get all my features + stories from all AND all my stories connected to other features - azure-devops

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

Related

How to list all child items of specific product backlog item

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.

Query for lastChanged Work Items across several projects

I'm trying to create query that gives me all user stories that has been updated within the last two days, which should be pretty basic within a project with the WorkItem Batch Query.
https://[TENNANT].analytics.visualstudio.com/[PROJECT]/_odata/v1.0/WorkItems
I will need to do an update back on some of the user stories where a certain set of criteria are set (calculations of estimations that I cannot do with the rules in DevOps as they are now)
My challenge is that we have 200 projects, and I need to get the last changed user stories across all these projects. So my current solution is as following:
Do a query for projects with paging of 100 (3 queries as it is now)
Do a query for User Stories with paging of 200 (207 queries as it is now)
Run through all User Stories and update calculations on the once that need (average about 20 per day)
All in all the query will run for about 11 minutes, and then fail due to throttling thresholds on Azure DevOps REST Api.
Is there a way I can query User Stories across all projects in our tenant, or query projects where user stories have been changed since?
LastChanged for projects are not related to underlaying elements, but the project meta data.
Would appreciate every hint there is to find a solution to this :)
Is there a way I can query User Stories across all projects in our
tenant, or query projects where user stories have been changed since?
You can try Azure Devops Rest Api Query By Wiql, so that you can customize the logic via WIQL syntax.
A simple request to return the User Stories which have been changed within the last two days in specific projects:
Post https://dev.azure.com/{OrgName}/_apis/wit/wiql?api-version=6.1-preview.2
Request body if you're querying all projects within the organization:
{
"query": "Select [System.Id] From WorkItems WHERE [System.WorkItemType]='User Story' AND [System.ChangedDate] >= #today-2 ORDER BY [System.ChangedDate] DESC"
}
Request body if you're querying specific projects within the organization:
{
"query": "Select [System.Id] From WorkItems WHERE [System.WorkItemType]='User Story' AND [System.ChangedDate] >= #today-2 And ([System.TeamProject] = 'ProjectName1' OR [System.TeamProject] ='ProjectName2') ORDER BY [System.ChangedDate] DESC"
}

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.

VSTS : Need list of users assigned to the story for their task

I have number of user-stories for my project. For each user story I have around 5 to 6 child task and each is assign to different people like PM, developer, QA etc.
Fetching user story and task wise user is easy.
But I want to fetch story and list of users associated with its child task.
Can you please guide me on this.
According to your description, I think query can meet your need. You should change the Type of query to Work items and direct links.
And then set the filters as follow.
You can get all child task and the User story which associated with child task. And in the Assigned To column, you can get the users assigned to the task.
Also you can use REST API to get the work items id.
Post https://dev.azure.com/{orgname}/{projectname}/_apis/wit/wiql?api-version=5.1 and input the follow WIQL in request body.
SELECT
[System.Id],
[System.WorkItemType],
[System.Title],
[System.AssignedTo],
[System.State],
[System.Tags]
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] = 'Task'
)
ORDER BY [System.Id]
MODE (MustContain)

TFS 2013 Kanban board Done column (multiple complete states)

In TFS 2013 Microsoft "fixed" a bug which allowed to map a WorkItem's state to the "Done" state in the Kanban board.
This feature was heavily used in our company. There is a petition to bring it back back but I don't think it will make it:
http://visualstudio.uservoice.com/forums/121579-visual-studio/suggestions/5589316-allow-multiple-complete-meta-state-mapping-in-tfs
In order to migrate TFS2012 to TFS2013 I would like to know where the customized "Done" state columns in TFS 2012 is stored in the database to create a report which shows which team used which WorkItem state as their "Done" state.
TFS2012 Kanban Board looked like that (note the dropdown):
TFS2013 Kanban Board looks like that (note NO dropdown):
I do have access to the TFS Collection database and I would like to create a SQL query which shows me all the customization of this column in TFS 2012.
How can I get for "My WorkItem" the for every Team Project and every Team the customized "Done" state in TFS2012 database?
What other tables do I need to link to in order to get those states?
So far I could only get the TeamId, Name, ColumnType ProjectId but not the effective WorkItem and the "Done" column customization. How can I do that?
SELECT
tbl_Board.TeamId,
tbl_Board.Revision,
tbl_BoardColumn.Name,
tbl_BoardColumn.ColumnType,
tbl_WorkItemTypeExtensions.Description,
tbl_BoardColumn.[Order],
tbl_WorkItemTypeExtensions.ProjectId
FROM
tbl_WorkItemTypeExtensions
RIGHT OUTER JOIN tbl_Board ON
tbl_WorkItemTypeExtensions.Id = tbl_Board.ExtensionId
LEFT OUTER JOIN tbl_BoardColumn ON
tbl_Board.Id = tbl_BoardColumn.BoardId
Experts do not recommend accessing TFS DB but you can use Tfs_WarehouseDatabase if Reporting is configured and Data from all project collections is collected and stored in tables that are optimized for reporting.
I do not have a knowledge about the db structures of TFS but going through few important online articles I managed understood quiet a few about it and as I understood the information that is required for you is in WorkItemsAretable.
Team Foundation Server Databases
Work item field and database schema reference
Stack overflow Question Access the Kanban Column (a Team-Specific Field) for a Work Item
With those queries below you can get the state of a certain work item on the Kanban board:
USE Tfs_DefaultCollection
SELECT TOP(10)
MarkerField + 1 as FieldId,
*
FROM tbl_WorkItemTypeExtensions with(nolock)
JOIN tbl_projects on tbl_WorkItemTypeExtensions.ProjectId = tbl_projects.project_id
WHERE tbl_projects.project_name LIKE '%ProjectName%
Copy the result from "FieldId" column to below's query at position XXXXXXXX
SELECT TOP 1000
wid.Id,
wia.State,
wid.StringValue as Kanban,
wia.[Work Item Type],
wia.Title,
tn.Name as Iteration
FROM tbl_WorkItemData wid with(nolock)
JOIN WorkItemsAre wia on wia.ID = wid.Id
JOIN TreeNodes tn on wia.IterationID = tn.ID
WHERE FieldId = XXXXXXXX and RevisedDate = '9999-01-01 00:00:00.000'
ORDER BY Id
Create a Detailed Report using Report Designer
Hope the sources that I have provided above will help your problem!
I contacted the Microsoft Support and they provided me the following answer to my question:
SELECT
board.TeamId,
boardColumn.Name,
workItemTypeExtensions.Rules
FROM
tbl_Board board JOIN
tbl_WorkItemTypeExtensions workItemTypeExtensions ON board.ExtensionId = workItemTypeExtensions.Id JOIN
tbl_projects projects ON workItemTypeExtensions.ProjectId = projects.project_id JOIN
tbl_BoardColumn boardColumn ON board.Id = boardColumn.BoardId
WHERE
projects.project_name LIKE '%< ENTER YOUR PROJECT NAME HERE >%' AND
boardColumn.ColumnType = 2
ORDER BY
board.TeamId,
boardColumn.[Order]
When I check XML in the "Rules" column there I can find exactly what I was looking for.