如何在 WIQL 工作项中获取层次结构

2023-12-27

我在 TFS 中有一个像这样的层次结构 其中 1 个功能可以有“N”个产品待办事项列表项目,而单个产品产品待办列表项目可以有“N”个任务/错误 树结构

特点1->
PB1->
任务1,任务2,任务3

my Query

string querystring = string.Format("select [System.Id], [System.Title],[Story.Author],[Story.Owner],[System.AssignedTo]," +
                " [System.WorkItemType],[Microsoft.VSTS.Scheduling.StoryPoints],[Microsoft.VSTS.Common.Priority]," +
                "[Microsoft.VSTS.Scheduling.Effort], [Actual.Effort.Completed]" +
                ",[System.State]," +
                "[System.IterationPath]" +
                " FROM WorkItemLinks" +
                " WHERE" +
                " ([Source].[System.TeamProject]='{0}'" +
                " and [Source].[System.IterationPath] UNDER 'MRI_SCRUM_GIT\\Pluse Pheonix\\Sprint 1'" +
                " and [Source].[System.WorkitemType]<>'' " +
                ")" +

                " and ([System.Links.LinkType]='System.LinkTypes.Hierarchy-Forward')" +
                " and ([Target].[System.WorkItemType] <> '' )" +
                " ORDER BY [System.Id] " +
               " mode (Recursive)", projectname);

Now how do i get all the fields in C# code like the below image enter image description here


以下网站上已经有一个代码片段:

https://learn.microsoft.com/en-us/vsts/integrate/quickstarts/work-item-quickstart https://learn.microsoft.com/en-us/vsts/integrate/quickstarts/work-item-quickstart

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using Microsoft.TeamFoundation.WorkItemTracking.WebApi;
using Microsoft.TeamFoundation.WorkItemTracking.WebApi.Models;
using Microsoft.VisualStudio.Services.Common;
using Microsoft.VisualStudio.Services.WebApi.Patch.Json;
using Microsoft.VisualStudio.Services.WebApi.Patch;
using Microsoft.VisualStudio.Services.WebApi;
using System.Net.Http.Headers;
using System.Net.Http;
using Newtonsoft.Json;

public class ExecuteQuery
{
    readonly string _uri;
    readonly string _personalAccessToken;
    readonly string _project;

    /// <summary>
    /// Constructor. Manually set values to match your account.
    /// </summary>
    public ExecuteQuery()
    {
        _uri = "https://accountname.visualstudio.com";
        _personalAccessToken = "personal access token";
        _project = "project name";
    }

    /// <summary>
    /// Execute a WIQL query to return a list of bugs using the .NET client library
    /// </summary>
    /// <returns>List of Microsoft.TeamFoundation.WorkItemTracking.WebApi.Models.WorkItem</returns>
    public List<WorkItem> RunGetBugsQueryUsingClientLib()
    {
        Uri uri = new Uri(_uri);
        string personalAccessToken = _personalAccessToken;
        string project = _project;

        VssBasicCredential credentials = new VssBasicCredential("", _personalAccessToken);

        //create a wiql object and build our query
        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"
        };

        //create instance of work item tracking http client
        using (WorkItemTrackingHttpClient workItemTrackingHttpClient = new WorkItemTrackingHttpClient(uri, credentials))
        {
            //execute the query to get the list of work items in the results
            WorkItemQueryResult workItemQueryResult = workItemTrackingHttpClient.QueryByWiqlAsync(wiql).Result;

            //some error handling                
            if (workItemQueryResult.WorkItems.Count() != 0)
            {
                //need to get the list of our work item ids and put them into an array
                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 ids found in query
                var workItems = workItemTrackingHttpClient.GetWorkItemsAsync(arr, fields, workItemQueryResult.AsOf).Result;

                Console.WriteLine("Query Results: {0} items found", workItems.Count);

                //loop though work items and write to console
                foreach (var workItem in workItems)
                {
                    Console.WriteLine("{0}          {1}                     {2}", workItem.Id, workItem.Fields["System.Title"], workItem.Fields["System.State"]);
                }

                return workItems;
            }

            return null;
        }
    }
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何在 WIQL 工作项中获取层次结构 的相关文章

随机推荐

  • Datomic 中的 SQL LIKE 运算符

    我想运行一个 sql 查询 给定一个搜索关键字 将找到所有用户 其中他们的名字与该模式匹配 即在原始 SQL 中类似WHERE users name LIKE foo 我该怎么做呢 查询的当前结构 gt defn find users db
  • 传单用户触发事件

    有什么方法可以确定事件是通过编程方式触发还是由用户触发 我们希望在地图移动或缩放时重新加载标记列表 但我们最初使用以下命令设置地图的边界setBounds http leafletjs com reference html rectangl
  • 使用 plyr 将参数传递给 R 函数

    我无法解决一个问题 想写一个这样的函数 f describe lt function data var by require plyr res lt ddply data by summarize N sum is na var Mean
  • 如何在react-native android应用程序中显示GIF?

    我想通过我的 android 反应本机应用程序中的图像标签中的 URL 显示一个简单的 gif 但是当我启动它时 没有显示图像 中提供的代码docs https facebook github io react native docs im
  • 在屏障实现中将代码从顺序一致性更改为不太严格的排序

    我遇到了这段代码 用于简单地实现屏障 对于无法使用的代码std experimental barrier在 C 17 中或std barrier在 C 20 中 在 C Concurrency in Action 一书中 编辑 屏障是一种同
  • 我们如何在azure应用程序洞察中显示数据库查询

    我们的应用程序正在使用天蓝色的应用程序见解 我读到的是 使用应用程序洞察端到端跟踪 我们甚至可以获得在数据库中执行的查询以及该查询花费了多少时间 但如屏幕截图所示 Azure App Insights 显示有 3 个对数据库的调用 但不是这
  • 将每个分隔符的值拆分为单独的行 - 批处理

    我正在尝试使用 delimiter 将 csv 文件的值拆分为单独的行 作为拆分点 IE csv file video1 video2 video3 video4 video5 video6 Preferred output video1
  • 获取 Twitter 请求令牌失败

    我按照以下说明进行操作http dev twitter com pages auth request token http dev twitter com pages auth request token 并开发了一个c 类来进行OAuth
  • 如何取消Java 8的完整未来?

    我正在玩 Java 8 completable futures 我有以下代码 CountDownLatch waitLatch new CountDownLatch 1 CompletableFuture
  • redshift - 如何插入表生成的时间序列

    我正在尝试在 Redshift 中生成时间序列并插入表中 但没有成功 到目前为止我已经尝试过 insert into date dateid date SELECT to char datum YYYYMMDD int AS dateid
  • 有没有办法判断是否显示软键盘?

    有没有办法判断软键盘是否显示在活动中 I tried InputMethodManager manager InputMethodManager getSystemService getApplicationContext INPUT ME
  • Android Camera2 API - 检测我们何时获得焦点

    因此 我设法用旧相机按照我想要的方式创建了我想要的功能 使用 mCamera autoFocus autoFocusCallback 我检测何时获得焦点并在预览模式下运行所需的代码 现在我很难掌握如何在camera2 API 中执行相同的操
  • 完整的日历适合容器并隐藏滚动

    我无法弄清楚如何缩放 fullcalendar 以适应它的父容器 我想在单个页面上为用户显示周视图 而无需滚动 因此他们可以快速查看一周的项目 如果我需要使文本变小 插槽高度变小等 我没问题 但我只是不确定如何根据浏览器窗口的大小动态地执行
  • 在 C# 中使用“out”关键字返回多个值

    我目前正在努力理解它的含义 当它说使用 out 关键字我们能够return多个值 例如 来自 msdn 站点 https msdn microsoft com en us library ee332485 aspx https msdn m
  • Python 中的通用命令模式和命令调度模式

    我正在寻找一个CommandPython 中的模式实现 根据维基百科 http en wikipedia org wiki Command pattern 命令模式是一种设计 对象用于的模式 代表并封装所有 调用方法所需的信息 稍后 我唯一
  • JS 对象文字和 JSON 字符串有什么区别?

    我对人们所说的对象文字 JSON JavaScript 对象的确切含义感到困惑 对我来说 它们看起来很相似 foo bar bar baz AFAIK 上面是对象文字 json 以及 javascript 对象 不是吗 对象字面量和 jso
  • 如何确保打印偶数奇数的两个线程在此实现中保持先偶后奇的顺序?

    我创建了两个可运行的作业 PrintEvenNumbersJob 和 PrintOddNumbersJob 并生成了两个线程来执行这些作业 这似乎工作得很好 但我对这个实施感到有些可疑 我可以对这个实施有一些意见和建议吗 我在这个实现中看到
  • Python 是强类型的吗?

    我遇到过一些链接 说 Python 是一种强类型语言 但是 我认为在强类型语言中你不能这样做 bob 1 bob bob 我认为强类型语言不接受运行时的类型更改 也许我对强 弱类型的定义错误 或过于简单 那么 Python 是强类型语言还是
  • jQuery 在 AJAX 请求时同时发送 GET 和 POST 参数

    如何使用 jQuery AJAX 请求同时发送 GET 和 POST 参数 我正在尝试添加do ajax id ID to url 但结果请求仅打磨至sss php没有查询字符串 获取部分 谢谢 ajax url sss php do aj
  • 如何在 WIQL 工作项中获取层次结构

    我在 TFS 中有一个像这样的层次结构 其中 1 个功能可以有 N 个产品待办事项列表项目 而单个产品产品待办列表项目可以有 N 个任务 错误 树结构 特点1 gt PB1 gt 任务1 任务2 任务3 my Query string qu