Retrieving work items and their linked work items in a single query using the TFS APIs

前端 未结 2 1951
悲&欢浪女
悲&欢浪女 2020-12-01 21:53

Does anyone know if it is possible to retrieve a list of work items and their linked work items in one trip from TFS using their TFS API web services?

相关标签:
2条回答
  • 2020-12-01 22:22

    The article you 're referring to in your answer presents with a method to do what you 're after, using WIQL. Certainly, not a bad choice.

    Another way, in my opinion better, is to simply generate graphically the query that yields the results you 're after. You probably need a simple "Work Items and Direct Link":
    enter image description here

    Once you 've saved that you 'll be able to:

    1. Open the query in VS & Team Web Access
    2. Tie the query with Excel & work on WIs from within Excel
    3. Catch the query results with TFS-API.

    For the latter part, supposing your query is named "MyLinkedQuery" and it resides under "Team Queries" of TeamProject "MyProj", you can do something like this:

    using System;
    using Microsoft.TeamFoundation.Client;
    using Microsoft.TeamFoundation.WorkItemTracking.Client;
    
    namespace LinkedQueryResults
    {
        class Program
        {
            static void Main()
            {
                TfsTeamProjectCollection teamProjectCollection = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri("http://TFSURL"));
    
                var workItemStore = (WorkItemStore)teamProjectCollection.GetService(typeof(WorkItemStore));
    
                var project = workItemStore.Projects["MyProj"];
                QueryHierarchy queryHierarchy = project.QueryHierarchy;
                var queryFolder = queryHierarchy as QueryFolder;
                QueryItem queryItem = queryFolder["Team Queries"];
                queryFolder = queryItem as QueryFolder;
    
                if (queryFolder != null)
                {
                    var myQuery = queryFolder["MyLinkedQuery"] as QueryDefinition;
                    if (myQuery != null)
                    {
                        var wiCollection = workItemStore.Query(myQuery.QueryText);
                        foreach (WorkItem workItem in wiCollection)
                        {
                            Console.WriteLine(workItem.Title); 
                        }
                    }
                }       
            }
        }
    }
    
    0 讨论(0)
  • 2020-12-01 22:22

    Found an article regarding this issue.

    It allows you to use a tree query, where you can get the parent item ids and it's linked items ids in one query. Using this, a second query can be used to get the actual detailed work item objects. Two queries to solve the issue.

    Edit: I also wrote a post about this on my blog.

    0 讨论(0)
提交回复
热议问题