Get all items from iteration - azure-devops

I am trying to get all work items from a given iteration. I can filter on TaskType on other fields. But not iteration paths. Am I missing something here?
var body = "{\"query\": \"Select [System.Id], [System.Title], [System.State],[System.IterationPath] From WorkItems Where [System.IterationPath] = 'GAC\\Sprint 10'\"}";
var json = await HTTP.POST("https://xxx.visualstudio.com/_apis/wit/wiql?api-version=5.1", body, personalaccesstoken);
return JsonConvert.DeserializeObject<WorkItemIdList>(json);

I can filter on TaskType on other fields. But not iteration paths.
Does below scripts is what you want?
SELECT [System.Id], [System.Title], [System.WorkItemType], [System.State], [System.IterationPath] FROM workitems WHERE [System.IterationPath] = 'MerConsoleApp\Q4' AND [system.WorkItemType] = 'Bug'
This WIQL can filter the Bug work items which located IterationPath is MerConsoleApp\Q4.
In addition, I saw you are applying this WIQL from api. There's one thing you need pay attention, you may not get exactly work item data if you run WIQL from rest api.
For example, since we specify fields in select, here we can get below data format while we run this WIQL from UI:
But for rest api, we defined and fixed the data structure of the work item as id + url. This means you can only get the satisfied work item id and its url, even if you has specified the [System.Id], [System.Title], [System.WorkItemType], [System.State] in it.

Related

Get all work items from a project azure devops REST API

I'm using Azure devops API to create a notification bot with AWS Lambda node.js. At this moment i need to check if each task work item is attached to a parent user story.
The first step will be to get all the task work items on "given" project, for this step i was reading azure devops api documentation and found this: Work Items - List
The API is asking for the id of the workitem that i want to get, but what if i need all the workitems from "given" project?
GET https://dev.azure.com/{organization}/{project}/_apis/wit/workitems?ids={ids}&api-version=5.1
Or is there any other way to get all the workitem ids from a given project?
You can use Work Items - Get Work Items Batch API that doesn't require ids but the maximum work items in the results are 200.
But, if you need to check Tasks, why you need get all the work items in the project? you can get only the Tasks, with Wiql - Query By Wiql API:
POST https://dev.azure.com/{organization}/{project}/{team}/_apis/wit/wiql?api-version=5.1
In the body make the query:
{
"query": "Select [System.Id], [System.Title], [System.State] From WorkItems Where [System.WorkItemType] = 'Task'"
}
Furthering Shayki's response regarding using a WIQL query, I'd suggest that you can have two birds with one stone here by doing a work item links query that looks for Tasks without a parent User Story:
POST https://dev.azure.com/{organization}/{project}/{team}/_apis/wit/wiql?api-version=5.1
request payload:
{
"query": "SELECT [System.Id] FROM workitemLinks WHERE ([Source].[System.WorkItemType] = 'Task') AND ([System.Links.LinkType] = 'System.LinkTypes.Hierarchy-Reverse') AND ([Target].[System.WorkItemType] = 'User Story') MODE (DoesNotContain)"
}
This way, you won't have to loop through each work item to then check if it has a parent.
Note: the WIQL query limits the results returned to 20K and returns an error if the query results in more work items than that. Further reason to use a query like the above, if applicable.
There is a client for C#:
public IEnumerable<int> GetIdList()
{
var connection = new VssConnection(new Uri("http://yourazuredevopsurl/"), new VssBasicCredential(string.Empty, personalAccessToken));
var workItemTrackingHttpClient = connection.GetClient<WorkItemTrackingHttpClient>();
var wiql = new Wiql
{
Query = $#"Select [System.Id] From WorkItems Where [System.WorkItemType] = 'Test Case'"
};
var worItemsIds = workItemTrackingHttpClient.QueryByWiqlAsync(wiql, "Project name").Result;
return worItemsIds.WorkItems.Select(reference => reference.Id);

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"
}

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)

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

how to get all the Work item for a Iteration path by TFS API?

I am currently using TFS API who's link is https://www.visualstudio.com/en-us/docs/integrate/api/wit/work-items#byids
currently, in my project I want to access all the Workitems who's iteration path= MRI_SCRUM_GIT http://apactfs.cbre.com:8080/tfs/CBRE.APAC.Applications/MRI_SCRUM_GIT/_workitems?_a=edit&id=61092
currently, i am finding a workitem number 6109 by this in postman GET
http://apactfs.cbre.com:8080/tfs/cbre.apac.applications/_apis/wit/workitems/61092?$expand=all&api-version=1.0
You need to execute a query to get all the Work item for a particular Iteration path. After executing a query, get the work items using the IDs that are returned in the query results response. You can get up to 200 work items at a time. Please refer to this article:
https://www.visualstudio.com/en-us/docs/integrate/api/wit/wiql#get-work-items
The sample is as below:
POST http://apactfs.cbre.com:8080/tfs/cbre.apac.applications/_apis/wit/wiql?api-version=1.0
Content-Type: application/json
{
"query": "Select [System.Id], [System.Title], [System.State] From WorkItems Where [System.IterationPath] under 'MRI_SCRUM_GIT'"
}