TFS API - WIQL - Query only returns id and url
Asked Answered
B

1

7

I am trying to execute a WIQL query on TFS server (following this example) and get work items with the tittle and other fields. Even though I define the columns I want on the output, the json returned only with id and url.

Query

 Select [System.Title],
    [System.Description],
    [System.WorkItemType],[System.Id]
    From WorkItems 
    Where [System.WorkItemType] = 'Task' 
       AND [State] <> 'Closed' 
       AND [State] <> 'Removed' 
      AND [System.AssignedTo] = @me 
    order by [Microsoft.VSTS.Common.Priority] asc, [System.CreatedDate] desc

Json returned

{"queryType":"flat","queryResultType":"workItem","asOf":"2016-03-18T22:53:15.777Z","columns":[{"referenceName":"System.Title","name":"Title","url":"http://<my tfs server>/tfs/DefaultCollection/_apis/wit/fields/System.Title"},{"referenceName":"System.Description","name":"Description","url":"http://<my tfs server>/tfs/DefaultCollection/_apis/wit/fields/System.Description"},{"referenceName":"System.WorkItemType","name":"Work Item Type","url":"http://<my tfs server>/tfs/DefaultCollection/_apis/wit/fields/System.WorkItemType"},{"referenceName":"System.Id","name":"ID","url":"http://<my tfs server>/tfs/DefaultCollection/_apis/wit/fields/System.Id"}],"sortColumns":[{"field":{"referenceName":"Microsoft.VSTS.Common.Priority","name":"Priority","url":"http://<my tfs server>/tfs/DefaultCollection/_apis/wit/fields/Microsoft.VSTS.Common.Priority"},"descending":false},{"field":{"referenceName":"System.CreatedDate","name":"Created Date","url":"http://<my tfs server>/tfs/DefaultCollection/_apis/wit/fields/System.CreatedDate"},"descending":true}],"workItems":[{"id":6760,"url":"http://<my tfs server>/tfs/DefaultCollection/_apis/wit/workItems/6760"},{"id":6734,"url":"http://<my tfs server>/tfs/DefaultCollection/_apis/wit/workItems/6734"},{"id":6731,"url":"http://<my tfs server>/tfs/DefaultCollection/_apis/wit/workItems/6731"},{"id":6526,"url":"http://<my tfs server>/tfs/DefaultCollection/_apis/wit/workItems/6526"},{"id":6525,"url":"http://<my tfs server>/tfs/DefaultCollection/_apis/wit/workItems/6525"},{"id":6524,"url":"http://<my tfs server>/tfs/DefaultCollection/_apis/wit/workItems/6524"},{"id":6514,"url":"http://<my tfs server>/tfs/DefaultCollection/_apis/wit/workItems/6514"},{"id":6372,"url":"http://<my tfs server>/tfs/DefaultCollection/_apis/wit/workItems/6372"},{"id":6371,"url":"http://<my tfs server>/tfs/DefaultCollection/_apis/wit/workItems/6371"},{"id":6235,"url":"http://<my tfs server>/tfs/DefaultCollection/_apis/wit/workItems/6235"},{"id":6218,"url":"http://<my tfs server>/tfs/DefaultCollection/_apis/wit/workItems/6218"},{"id":6123,"url":"http://<my tfs server>/tfs/DefaultCollection/_apis/wit/workItems/6123"},{"id":6122,"url":"http://<my tfs server>/tfs/DefaultCollection/_apis/wit/workItems/6122"},{"id":6121,"url":"http://<my tfs server>/tfs/DefaultCollection/_apis/wit/workItems/6121"},{"id":6120,"url":"http://<my tfs server>/tfs/DefaultCollection/_apis/wit/workItems/6120"}]}

Is there any flag that I should pass to the query so I can get those fields on the ouput?

Bichloride answered 18/3, 2016 at 23:1 Comment(0)
B
10

The question, from what I can tell at face value, is based on the first POST example provided on the documentation page you referenced.

Looking at the contents of your json result you'll notice the following json array:

"workItems":[
{"id":7331, 
"url":"https://<hostname>/tfs/<collection>/_apis/wit/workItems/7331"}, ... etc.

Reading on in the documentation page referenced the following is stated:

"After executing your 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."

This means the query is a two step process

1. retrieve a list of work item id's in the first call.

2. retrieve more detail on the workitems returned in the first api call by making additional calls.

The reason for the 200 work item limit makes sense, the responsiveness of the service would be negatively impacted if there was no such limit.

The documentation then continues on to provide a concise example of getting data for each of the work item IDs returned (in the workItems array) from the first api invocation.

Referenced example (from the same doc) below, note that the ID's returned in the first query would be used in this query:

GET: https://fabrikam.visualstudio.com/DefaultCollection/_apis/wit/WorkItems?ids=300,299,298,17,16,15,14,9,8&fields=System.Id,System.Title,System.State&asOf=2014-12-29T20:49:34.617Z&api-version=1.0

bottom line: At this point, there is no flag that forces the api to return all workitems resulting from the initial query.

Bemuse answered 19/3, 2016 at 18:13 Comment(2)
Thanks for the response. My problem here is not regarding the number of work items returned, it is about the fields returned in the workitem property. As you can see in my example, it only returns id and url, even though I explicitly declared that I want [System.Title], System.Description], [System.WorkItemType] and [System.Id] in the WIQL query.Bichloride
Yes agreed. The nuance I agree is a tad misleading, the initial query in my mind also does not require the additional fields specified, I personally believe the VS product team should update that document to reflect the reasoning. The point is though that this is a two step process. The initial query will only return a list of ID's, then its up to the client to query for the work item details in batches of 200 to prevent overloading the service. Imagine writing a query that returns all work items, example we have 1040000 workitems in our tfs instance dating back all the way to 2008. not good.Bemuse

© 2022 - 2024 — McMap. All rights reserved.