public void GetWorkItems() { WorkItem wi = new WorkItem(DefaultWorkItemType) { Title = "Work Item Created Using WIT OM" }; wi.Save(); WorkItemsAdded.Add(wi.Id); wi.Close(); var workItemsList = string.Join(",", WorkItemsAdded); // Can get multiple work items by using a wiql query string wiql = $"Select [System.Id], [System.Title], [System.State] From WorkItems Where [System.Id] In ({workItemsList})"; WorkItemCollection wiqlQueryResults = WIStore.Query(wiql); Console.WriteLine($"Wiql query searching for work items in ({workItemsList}) returned {wiqlQueryResults.Count} values"); Console.WriteLine(); // Alternatively, you can specify the ids as a collection, and a wiql for columns to return string columnWiql = $"Select [System.Id], [System.Title], [System.State] From WorkItems "; WorkItemCollection idAndColumnWiqlResults = WIStore.Query(WorkItemsAdded.ToArray(), columnWiql); Console.WriteLine($"Query searching for work items in ({workItemsList}) returned {idAndColumnWiqlResults.Count} values"); Console.WriteLine(); }
public void QueryByWiql() { string queryByTypeWiql = $"Select [System.Id], [System.Title], [System.State] From WorkItems Where [System.WorkItemType] = '{DefaultWorkItemType.Name}' and [System.TeamProject] = '{TeamProject.Name}'"; WorkItemCollection typeQueryResults = WIStore.Query(queryByTypeWiql); Console.WriteLine($"The wiql query returned {typeQueryResults.Count} results:"); foreach (WorkItem result in typeQueryResults) { Console.WriteLine($"WorkItem Id: '{result.Id}' Title: '{result.Title}'"); } Console.WriteLine(); }