You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Azure DevOps中能否将Query ID作为筛选条件用于POST请求?

如何基于已保存查询执行额外筛选(Azure DevOps WIQL)

Azure DevOps的WIQL API不支持直接在POST请求中传入Query ID来叠加额外筛选条件,不过你可以通过以下步骤实现需求:先获取已保存查询的原始WIQL语句,再修改语句添加自定义筛选后用POST执行。

步骤1:获取已保存查询的原始WIQL语句

先用GET请求调用查询详情接口,拿到已保存查询的完整WIQL定义:

GET https://dev.azure.com/{organization}/{project}/_apis/wit/queries/{id}?api-version=7.1-preview.2

响应里的query字段就是该已保存查询的原始WIQL语句,示例返回如下:

{
  "query": "Select [System.Id], [System.Title], [System.State] From WorkItems Where [System.WorkItemType] = 'Risk' AND [State] <> 'Closed' AND [State] <> 'Removed' order by [Microsoft.VSTS.Common.Priority] asc, [System.CreatedDate] desc"
}

步骤2:修改WIQL添加额外筛选

在原始WIQL的Where子句后追加你的额外条件(注意逻辑运算符和括号优先级),比如新增“优先级为1”的筛选规则:

Select [System.Id], [System.Title], [System.State] 
From WorkItems 
Where [System.WorkItemType] = 'Risk' 
  AND [State] <> 'Closed' 
  AND [State] <> 'Removed' 
  AND [Microsoft.VSTS.Common.Priority] = 1  -- 新增的自定义筛选条件
order by [Microsoft.VSTS.Common.Priority] asc, [System.CreatedDate] desc

如果需要调整排序规则,直接修改order by部分即可。

步骤3:用POST请求执行修改后的WIQL

把修改好的WIQL放到POST请求体中执行:

POST https://dev.azure.com/{organization}/{project}/_apis/wit/wiql?api-version=7.1-preview.2
Content-Type: application/json

请求体示例:

{
  "query": "Select [System.Id], [System.Title], [System.State] From WorkItems Where [System.WorkItemType] = 'Risk' AND [State] <> 'Closed' AND [State] <> 'Removed' AND [Microsoft.VSTS.Common.Priority] = 1 order by [Microsoft.VSTS.Common.Priority] asc, [System.CreatedDate] desc"
}

注意事项

  • 如果已保存查询是树形查询(Tree query),WIQL语法会包含Hierarchy关键字,修改时要保留树形结构逻辑,示例:
    Select [System.Id], [System.Title] 
    From WorkItemLinks 
    Where Source.[System.WorkItemType] = 'Epic' 
      And Target.[System.State] <> 'Closed'
      And Target.[Microsoft.VSTS.Common.Priority] = 1  -- 新增筛选
      Order By [System.Id] Mode(Recursive)
    
  • 拼接条件时注意逻辑运算符(AND/OR)的优先级,必要时用括号分组,避免筛选逻辑出错。

内容的提问来源于stack exchange,提问作者Seth Zhang

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.03 08:14:55