7

我正在尝试在 TFS 服务器上执行 WIQL 查询(按照示例)并获取带有标题和其他字段的工作项。即使我在输出中定义了我想要的列,json 也只返回了 id 和 url。

询问

 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

杰克逊回来了

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

是否有任何标志我应该传递给查询,以便我可以在输出中获取这些字段?

4

1 回答 1

10

从表面上看,这个问题是基于您引用的文档页面上提供的第一个POST示例。

查看 json 结果的内容,您会注意到以下 json 数组:

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

在参考的文档页面中阅读以下内容:

“执行查询后,使用查询结果响应中返回的 ID 获取工作项。一次最多可以获取 200 个工作项。”

这意味着查询是一个两步过程

1.在第一次调用中检索工作项 ID 列表。

2.通过进行其他调用,检索第一次 api 调用中返回的工作项的更多详细信息。

200 个工作项限制的原因是有道理的,如果没有这样的限制,服务的响应能力将受到负面影响。

然后,文档继续提供一个简明示例,用于获取从第一个 api 调用返回的每个工作项 ID(在workItems数组中)的数据。

下面引用的示例(来自同一文档),请注意,在第一个查询中返回的 ID 将在此查询中使用:

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

底线:此时,没有标志强制 api 返回初始查询产生的所有工作项。

于 2016-03-19T18:13:43.853 回答