Trond Jelsnes Undrum
Trond Jelsnes Undrum

Reputation: 113

Query for lastChanged Work Items across several projects

I'm trying to create query that gives me all user stories that has been updated within the last two days, which should be pretty basic within a project with the WorkItem Batch Query. https://[TENNANT].analytics.visualstudio.com/[PROJECT]/_odata/v1.0/WorkItems I will need to do an update back on some of the user stories where a certain set of criteria are set (calculations of estimations that I cannot do with the rules in DevOps as they are now)

My challenge is that we have 200 projects, and I need to get the last changed user stories across all these projects. So my current solution is as following:

  1. Do a query for projects with paging of 100 (3 queries as it is now)
  2. Do a query for User Stories with paging of 200 (207 queries as it is now)
  3. Run through all User Stories and update calculations on the once that need (average about 20 per day)

All in all the query will run for about 11 minutes, and then fail due to throttling thresholds on Azure DevOps REST Api.

Is there a way I can query User Stories across all projects in our tenant, or query projects where user stories have been changed since? LastChanged for projects are not related to underlaying elements, but the project meta data.

Would appreciate every hint there is to find a solution to this :)

Upvotes: 0

Views: 449

Answers (1)

LoLance
LoLance

Reputation: 28096

Is there a way I can query User Stories across all projects in our tenant, or query projects where user stories have been changed since?

You can try Azure Devops Rest Api Query By Wiql, so that you can customize the logic via WIQL syntax.

A simple request to return the User Stories which have been changed within the last two days in specific projects:

Post https://dev.azure.com/{OrgName}/_apis/wit/wiql?api-version=6.1-preview.2

Request body if you're querying all projects within the organization:

{
  "query": "Select [System.Id] From WorkItems WHERE [System.WorkItemType]='User Story' AND [System.ChangedDate] >= @today-2 ORDER BY [System.ChangedDate] DESC"
}

Request body if you're querying specific projects within the organization:

{
  "query": "Select [System.Id] From WorkItems WHERE [System.WorkItemType]='User Story' AND [System.ChangedDate] >= @today-2 And ([System.TeamProject] = 'ProjectName1' OR [System.TeamProject] ='ProjectName2') ORDER BY [System.ChangedDate] DESC"
}

Upvotes: 1

Related Questions