I've been looking at several Microsoft code samples for using WorkItemTrackingHttpClient.QueryByWiqlAsync()
, and they all specify a number of fields in addition to the "Id" field.
For example, from this code sample:
Wiql wiql = new Wiql()
{
Query = "Select [State], [Title] " +
"From WorkItems " +
"Where [Work Item Type] = 'Bug' " +
"And [System.TeamProject] = '" + project + "' " +
"And [System.State] <> 'Closed' " +
"Order By [State] Asc, [Changed Date] Desc"
};
Then the code goes on to use this query:
WorkItemQueryResult workItemQueryResult =
workItemTrackingHttpClient.QueryByWiqlAsync(wiql).Result;
But then the following code extracts only the IDs from the query and uses them to get the actual work items, using workItemTrackingHttpClient.GetWorkItemsAsync()
:
List<int> list = new List<int>();
foreach (var item in workItemQueryResult.WorkItems)
{
list.Add(item.Id);
}
int[] arr = list.ToArray();
//build a list of the fields we want to see
string[] fields = new string[3];
fields[0] = "System.Id";
fields[1] = "System.Title";
fields[2] = "System.State";
//get work items for the id's found in query
var workItems = workItemTrackingHttpClient.GetWorkItemsAsync(arr, fields, workItemQueryResult.AsOf).Result;
I discovered that you only need to "Select [Id] FROM workitems ..."
, because only the ID is actually used. In fact, I can find no direct way of accessing the other fields in the WorkItemQueryResult
results returned from QueryByWiqlAsync()
.
So what am I missing? Why do all the Microsoft code samples specify a variety of columns for the query, but then just ignore them all? Is it just a mistake, or is there some fundamental reason that I'm unaware of?
My guess is that they copied the WIQL expression from an existing query.
As the REST API only returns the IDs and the .NET client libraries for Azure DevOps are just a thin wrapper around the REST API, the client libraries can't surface data that isn't returned by the REST API.
See the example response (shortened by me) from the docs
{
"queryType": "flat",
"asOf": "2014-12-29T20:49:34.617Z",
"columns": [
{
"referenceName": "System.Id",
"name": "ID",
"url": "https://dev.azure.com/fabrikam/_apis/wit/fields/System.Id"
},
{
"referenceName": "System.Title",
"name": "Title",
"url": "https://dev.azure.com/fabrikam/_apis/wit/fields/System.Title"
},
{
"referenceName": "System.State",
"name": "State",
"url": "https://dev.azure.com/fabrikam/_apis/wit/fields/System.State"
}
],
"sortColumns": [
{
"field": {
"referenceName": "Microsoft.VSTS.Common.Priority",
"name": "Priority",
"url": "https://dev.azure.com/fabrikam/_apis/wit/fields/Microsoft.VSTS.Common.Priority"
},
"descending": false
},
{
"field": {
"referenceName": "System.CreatedDate",
"name": "Created Date",
"url": "https://dev.azure.com/fabrikam/_apis/wit/fields/System.CreatedDate"
},
"descending": true
}
],
"workItems": [
{
"id": 300,
"url": "https://dev.azure.com/fabrikam/_apis/wit/workItems/300"
},
{
"id": 299,
"url": "https://dev.azure.com/fabrikam/_apis/wit/workItems/299"
}
]
}