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

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.

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.

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

OData Query to Only Return State Changes from Azure Devops

I have an OData Query that I am using to pull data into PowerBI that I am trying to make more efficient. I am doing a report from Azure DevOps and pulling data in from the WorkItemRevisions resource. Currently, I am pulling all the data for a Work Item and then filtering in PowerBI to only get when the State has changed. I would like to move this filtering to the Odata query so that I can minimize the data that I am pulling into the report.
Currently, I have a query like the following (simplified example used for this question)
https://analytics.dev.azure.com/{Organization}/{Project}/_odata/v3.0-preview/WorkItemRevisions?
$select=Revision,WorkItemId,WorkItemType,Title,State,ChangedDate,LeadTimeDays,ParentWorkItemId
How can this be updated so that only Revisions where the State has changed (from New to Active, Active to Done, etc) are returned?
How can this be updated so that only Revisions where the State has changed (from New to Active, Active to Done, etc) are returned?
I am afraid that OData Query could not perfectly achieve what we need.
There is a feature Revisions/any(r:r/state eq '{state}') to filter the work item has a set state in the past.
For example:
https://analytics.dev.azure.com/<Organization>/<Project>/_odata/v2.0//WorkItems?
$filter=State eq 'Closed' and Revisions/any(r:r/State eq 'Active')
This query is similar to a Work Item query that uses the Was Ever operator.
As I said, this may not be a perfect solution. That because it can only filter whether the work item has ever had a specified states, but cannot accurately determine the states of the work item must be from New to Active, Active to Done. If we change the state of the workitem from Active to Resolved, then change it from Resolved to Closed. Then this work item will appear in the query results.
In addition, even if you use the UI query, we cannot accurately query the result of the work item status changing from A to B. To achieve this goal, we need to use REST API.
So, we could use the feature Revisions/any(r:r/state eq '{state}') to reduce the data pulled into the report to a certain extent.
You can use below query to achieve what you want.
/_odata/v4.0-preview/WorkItemRevisions?&$apply=filter(((WorkItem/WorkItemType
eq 'Bug' or WorkItem/WorkItemType eq 'Product Backlog Item') and
((WorkItem/ChangedDate ge 2022-10-05Z and WorkItem/ChangedDate le
2022-11-04Z) or (WorkItem/CreatedDate ge 2022-10-05Z and
WorkItem/CreatedDate le 2022-11-04Z))))/groupby((WorkItemId,State),
aggregate(ChangedDate with min as MinChangedDate))
To filter the group by data you need to encapsulate it under $apply as it is shown above.
Above URL will return all states and their changed dates for Bug and PBI Work Item types which are added or updated with a given date range.
Hope it helps!
if you are able to use Analytics Views instead of OData, there is a dedicated field available in Analytics Views Fields setting called "State Changed Date"

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)

Creating a VSTS Extension, using WIQL query to grab work item data, can I grab Activity field data?

I'm creating a Visual Studio Team Services extension that in it's current iteration is supposed to display child tasks for development, testing, etc. that were added to a work item. I build a WIQL query to get these tasks and some data about them.
In VSTS (and TFS), tasks have an Activity field, which I want, to differentiate between the different types of tasks (development, testing, etc.). However, I'm finding with the below WIQL query I create, I get the following error: TF51005: The query references a field that does not exist. The error is caused by «[System.Activity]». Is there a way I can get access to the Activity field for those tasks? Or is it just not supported currently?
SELECT [System.Id], [System.WorkItemType], [System.Title],
[System.Activity], [System.State]
FROM WorkItemLinks
WHERE (Source.[System.TeamProject] = 'someProjectID'
AND Source.[System.Id] = someWorkItemID
AND Source.[System.State] <> 'Removed')
AND ([System.Links.LinkType] = 'System.LinkTypes.Hierarchy-Forward')
AND (Target.[System.WorkItemType] = 'Task')
MODE(Recursive)
Working through this I discovered https://marketplace.visualstudio.com/items?itemName=ottostreifel.wiql-editor, which has helped make it alot easier debugging my WIQL query. I highly recommend it to anyone who is new to working with WIQL.
You can create a query with necessary fields in web access, then get detail wiql by using Get a query or folder REST API (add $expand=wiql parameter).
I looked some more and discovered my answer, apparently Microsoft.VSTS.Common.Activity is the field you want to reference to get the activity for the task. I found it here: https://www.visualstudio.com/en-us/docs/work/track/query-numeric. Looks like there's some more information there about some data you can grab, like Microsoft.VSTS.Scheduling.StoryPoints. However it's definitely not a complete list, and I wasn't able to find one. Feel free to comment on this if you know of a complete list of references to use to grab anything you want about a work item!