Reputation: 11
In VSTS, I get this when there are more than 20k work items returned by a wiql query. I wanted to know if there is a parameter to limit the number of work items returned(even though the actual query may return 20000+ work items)?
Caused by: com.microsoft.tfs.core.ws.runtime.exceptions.SOAPFault: VS402337: The number of work items returned exceeds the size limit of 20000. Change the query to return fewer items.
Upvotes: 1
Views: 3949
Reputation: 19391
In this case, Andy gave two methods to fix this issue, you can refer to it.
1.Add the Query conditions to return fewer items just as the error message mentioned.
For example: SELECT * FROM WorkItems WHERE [System.TeamProject] = @project AND [System.State] = ‘Active' AND [System.AssignedTo] = ‘joselugo'
2.Split into groups to return them separately.
// There is a VSO limit of a query returning 20,000 results. Split into groups of 10,000 items maximum.
var results = new List<WorkItemReference>();
var counter = 10000;
var moreResults = true;
while (moreResults)
{
List<WorkItemReference> currentResults = this.WitClient.QueryByWiqlAsync(new Wiql
{
Query = $"SELECT System.ID FROM WorkItems WHERE System.TeamProject = '{Project}' AND {customQuery} AND System.ID >= {counter - 10000} AND System.ID < {counter}"}).Result.WorkItems.ToList();
if (currentResults.Count == 0)
{
// Verify there are no more items
try
{
results.AddRange(this.WitClient.QueryByWiqlAsync(new Wiql
{
Query = $"SELECT System.ID FROM WorkItems WHERE System.TeamProject = '{Project}' AND {customQuery} AND System.ID >= {counter}"
}).Result.WorkItems.ToList());
moreResults = false;
}
catch (Exception e)
{
if (e.ToString().Contains("VS402337"))
{
// There are still more results, so increment and try again.
}
else
{
throw;
}
}
}
else
{
results.AddRange(currentResults);
}
counter += 10000;
}
This workaround is for .net tfs sdk, I think you are using java tfs sdk, you can refer to the above code logic to modify.
Upvotes: 1