Reputation: 31
We're using TFS19 Update 1.
We added a new field and we want to change all queries that used until now old field, to use this new one.
For that, first we need to find all queries that used the old field and then changed them manually or with other-script/continues-script.
How can I find all queries wiql?
Trying to use Rest Api get method:
http://tfs19-app-test:8080/tfs/CollectionName/ProjectName/_apis/wit/queries?$expand=all&$depth=2&api-version=5.0
And I get only a small part of my queries, we have a lot of folders inside folders...
Upvotes: 0
Views: 1505
Reputation: 33698
Sample:
static void GetQueryClientAPI()
{
VssCredentials Credentials = new VssCredentials(new Microsoft.VisualStudio.Services.Common.VssBasicCredential(string.Empty, "Personal access token"));
TfsTeamProjectCollection tpc = new TfsTeamProjectCollection(new Uri("TFS URL"), Credentials);
tpc.EnsureAuthenticated();
Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItemStore wis = tpc.GetService(typeof(Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItemStore)) as Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItemStore;
Microsoft.TeamFoundation.WorkItemTracking.Client.QueryHierarchy qh = wis.Projects["Demo"].QueryHierarchy;
foreach (Microsoft.TeamFoundation.WorkItemTracking.Client.QueryItem q in qh)
{
GetChildQuery(q);
}
Console.Read();
}
static void GetChildQuery(Microsoft.TeamFoundation.WorkItemTracking.Client.QueryItem query)
{
if (query is Microsoft.TeamFoundation.WorkItemTracking.Client.QueryFolder)
{
Microsoft.TeamFoundation.WorkItemTracking.Client.QueryFolder queryFolder = query as Microsoft.TeamFoundation.WorkItemTracking.Client.QueryFolder;
foreach (var q in queryFolder)
{
GetChildQuery(q);
}
}
else
{
Microsoft.TeamFoundation.WorkItemTracking.Client.QueryDefinition querydef = query as Microsoft.TeamFoundation.WorkItemTracking.Client.QueryDefinition;
Console.WriteLine(querydef.Name + " -- " + querydef.Path);
}
}
The package: Microsoft.TeamFoundationServer.ExtendedClient
Upvotes: 0
Reputation: 41575
When you run your API:
http://tfs19-app-test:8080/tfs/CollectionName/ProjectName/_apis/wit/queries?$expand=all&$depth=2&api-version=5.0
You get a small response with only 2 values:
Shared Queries
My Queries
Then you need to check the children
property of them. if the child is query - good. if it's a folder, you will see another children
property but now without full results, you need to perform the Queries - Get API to get this specific folder and then check the childern
.
$url = "http://tfs19-app-test:8080/tfs/CollectionName/ProjectName/_apis/wit/queries?$expand=all&$depth=2&api-version=5.0"
$repsonse = Invoke-RestMethod -Uri $url -Method Get -ContentType application/json -UseDefaultCredentials
# The $repsonse.value is array of 2 types. $repsonse.value.name:
# - Shared Queries
# - My Queries
# $repsonse.value[0].children = all the quries inside the Shared Queries
# Now iterate the value and check if you see `hasChildren` = True, if yes call the get query api
Upvotes: 1