How do I query azure dev ops to view stories that were added after sprint start
Assistant
User
How would you create a query for user stories for average story points for a sprint
Assistant
To create a query for user stories to calculate the average story points for a sprint in Azure DevOps, you can follow these steps:
Create a new query: In Azure DevOps, navigate to the "Boards" section, then click on "Queries" and "New Query."
User
how do you query for stories not in past sprints using current iteration
Assistant
To query for user stories that are not in past sprints using the current iteration in Azure DevOps, you can follow these steps:
Create a new query: In Azure DevOps, navigate to the "Boards" section, then click on "Queries" and "New Query."
Set the query parameters: In the query editor, set the following parameters:
Set this to "User Story" to filter only user stories.
User
how do you query for stories not in a sprint that are closed within a specific time period
Assistant
To query for user stories that are not in a sprint and are closed within a specific time period in Azure DevOps, you can follow these steps:
User
how do I create a dashboard tile for a customer field and have it look like the chart for work items
Assistant
To create a dashboard tile for a custom field in Azure DevOps that looks like the chart for work items, you can follow these steps:
Create a query for the custom field: First, create a query that filters work items based on the custom field you want to visualize. Here's an example of how to create a query for a custom field named "CustomField":
Navigate to the "Boards" section, then click on "Queries" and "New Query."
Set the query parameters:
Work Item Type: Set this to the work item type you want to visualize (e.g., "User Story").
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
To query Azure DevOps for stories that were added after the sprint start, you can use the Work Items - Query API with a Wiql query. Here's a step-by-step guide:
Create a Personal Access Token (PAT): If you don't have one already, create a PAT with the necessary permissions (at least 'Work items (read)' scope) in Azure DevOps. You can create a PAT by going to your Azure DevOps profile, clicking on 'Security', and then 'Personal Access Tokens'.
Construct the Wiql query: You can use the following Wiql query to find stories added after the sprint start. Replace [YourProjectName] and [YourSprintName] with the actual names of your project and sprint. The query filters work items based on the 'System.CreatedDate' field and the start date of the sprint.
code
{
"query": "SELECT [System.Id], [System.Title], [System.CreatedDate] FROM workitems WHERE [System.WorkItemType] = 'User Story' AND [System.TeamProject] = '[YourProjectName]' AND [System.IterationPath] = '[YourSprintName]' AND [System.CreatedDate] > @Today - 14"
}
The @Today - 14 part of the query assumes that your sprints are two weeks long. Adjust the number of days accordingly if your sprints have a different duration.
Run the query using the API: You can use a tool like Postman or curl to run the query. Here's an example using curl:
bash
curl -u :<your_pat> -H "Content-Type: application/json" -d '{ "query": "SELECT [System.Id], [System.Title], [System.CreatedDate] FROM workitems WHERE [System.WorkItemType] = \'User Story\' AND [System.TeamProject] = \'[YourProjectName]\' AND [System.IterationPath] = \'[YourSprintName]\' AND [System.CreatedDate] > @Today - 14" }' https://dev.azure.com/<your_organization>/<your_project>/_apis/wit/wiql?api-version=6.0
Replace <your_pat>, <your_organization>, and <your_project> with the actual values.
Parse the response: The API will return a JSON response containing the work items that match the query. You can parse the response to extract the information you need. Here's an example of how to parse the response using Python:
python
import json
import requests
response = requests.post(
'https://dev.azure.com/<your_organization>/<your_project>/_apis/wit/wiql?api-version=6.0',
headers={'Content-Type': 'application/json'},
data=json.dumps({
"query": "SELECT [System.Id], [System.Title], [System.CreatedDate] FROM workitems WHERE [System.WorkItemType] = 'User Story' AND [System.TeamProject] = '[YourProjectName]' AND [System.IterationPath] = '[YourSprintName]' AND [System.CreatedDate] > @Today - 14"
}),
auth=('', '<your_pat>')
)
work_items = response.json()['workItems']
for work_item in work_items:
print(f"ID: {work_item['id']}, Title: {work_item['fields']['System.Title']}, Created Date: {work_item['fields']['System.CreatedDate']}")
This should help you query Azure DevOps for stories that were added after the sprint start.
Set the query parameters: In the query editor, set the following parameters:
Work Item Type: Set this to "User Story" to filter only user stories.
Team Project: Choose the project you're working on.
Iteration Path: Set this to the sprint you want to analyze. For example, if your sprint is named "Sprint 1," set the iteration path to "YourProjectName\Sprint 1."
Add columns: Click on "Columns" and add the following columns:
ID: This is the work item ID.
Title: This is the user story title.
Story Points: This is the field that contains the story points for each user story. If you're using a custom field for story points, replace "Story Points" with the name of your custom field.
Group by and calculate the average: To calculate the average story points, you need to group the user stories by a common field and then calculate the average. Since we want the average for the entire sprint, we can group by a constant value. Here's how to do it:
Click on "Group by" and select "New Group."
In the "Group by" dropdown, select "Constant."
In the "Value" field, enter any constant value, e.g., "1." This will group all user stories into a single group.
Click on "Add Column" and select "Aggregate."
In the "Aggregate" dropdown, select "Average."
In the "Field" dropdown, select "Story Points" (or your custom field for story points).
Save and run the query: Save the query and give it a name, e.g., "Average Story Points for Sprint." Run the query, and you'll see the average story points for the selected sprint.
Here's an example of the Wiql query you can use if you prefer to use the API:
code
{
"query": "SELECT [System.Id], [System.Title], [Microsoft.VSTS.Scheduling.StoryPoints] FROM workitems WHERE [System.WorkItemType] = 'User Story' AND [System.TeamProject] = 'YourProjectName' AND [System.IterationPath] = 'YourProjectName\\Sprint 1' GROUP BY '1' INTO @{AverageStoryPoints=AVG([Microsoft.VSTS.Scheduling.StoryPoints])}"
}
Replace YourProjectName and Sprint 1 with the actual names of your project and sprint. Also, replace Microsoft.VSTS.Scheduling.StoryPoints with the name of your custom field for story points if you're using one.
Work Item Type:
Team Project: Choose the project you're working on.
Iteration Path: Set this to the current iteration. For example, if your current iteration is named "Sprint 5," set the iteration path to "YourProjectName\Sprint 5."
Add a filter for past sprints: To exclude user stories from past sprints, you need to add a filter for the iteration path. Here's how to do it:
Click on "Add filter" and select "Iteration Path."
Set the operator to "Not Under."
In the value field, enter the path to the parent node of all past sprints. For example, if your past sprints are under "YourProjectName\Sprints," enter "YourProjectName\Sprints." This will exclude all user stories that are in any of the past sprints.
Add columns: Click on "Columns" and add the following columns:
ID: This is the work item ID.
Title: This is the user story title.
Iteration Path: This is the field that contains the iteration path for each user story. This will help you verify that the user stories are not in past sprints.
Save and run the query: Save the query and give it a name, e.g., "User Stories Not in Past Sprints." Run the query, and you'll see the user stories that are not in past sprints and are in the current iteration.
Here's an example of the Wiql query you can use if you prefer to use the API:
code
{
"query": "SELECT [System.Id], [System.Title], [System.IterationPath] FROM workitems WHERE [System.WorkItemType] = 'User Story' AND [System.TeamProject] = 'YourProjectName' AND [System.IterationPath] = 'YourProjectName\\Sprint 5' AND [System.IterationPath] NOT UNDER 'YourProjectName\\Sprints'"
}
Replace YourProjectName, Sprint 5, and Sprints with the actual names of your project, current iteration, and the parent node of all past sprints, respectively.
Create a new query: In Azure DevOps, navigate to the "Boards" section, then click on "Queries" and "New Query."
Set the query parameters: In the query editor, set the following parameters:
Work Item Type: Set this to "User Story" to filter only user stories.
Team Project: Choose the project you're working on.
Add filters for the time period and state: To filter user stories that are closed within a specific time period and are not in a sprint, you need to add the following filters:
Click on "Add filter" and select "State." Set the operator to "Was Ever" and the value to "Closed." This will include user stories that were closed at any point in time.
Click on "Add filter" again and select "Changed Date." Set the operator to ">" (greater than) and enter the start date of the time period you want to analyze. For example, if you want to analyze user stories closed in the last month, enter a date one month ago.
Click on "Add filter" again and select "Iteration Path." Set the operator to "Does Not Contain" and enter the path to the parent node of all sprints. For example, if your sprints are under "YourProjectName\Sprints," enter "YourProjectName\Sprints." This will exclude all user stories that are in any of the sprints.
Add columns: Click on "Columns" and add the following columns:
ID: This is the work item ID.
Title: This is the user story title.
State: This is the field that contains the state of each user story. This will help you verify that the user stories are closed.
Changed Date: This is the field that contains the date when the user story was last changed. This will help you verify that the user stories were closed within the specified time period.
Save and run the query: Save the query and give it a name, e.g., "Closed User Stories Not in Sprints." Run the query, and you'll see the user stories that are not in sprints and were closed within the specified time period.
Here's an example of the Wiql query you can use if you prefer to use the API:
code
{
"query": "SELECT [System.Id], [System.Title], [System.State], [System.ChangedDate] FROM workitems WHERE [System.WorkItemType] = 'User Story' AND [System.TeamProject] = 'YourProjectName' AND [System.State] WAS EVER 'Closed' AND [System.ChangedDate] > '2022-03-01' AND [System.IterationPath] DOES NOT CONTAIN 'YourProjectName\\Sprints'"
}
Replace YourProjectName, 2022-03-01, and Sprints with the actual names of your project, the start date of the time period, and the parent node of all sprints, respectively.
Team Project: Choose the project you're working on.
Add a filter for the custom field:
Click on "Add filter" and select "CustomField."
Set the operator to "=" (equals) and enter the value you want to filter by.
Save the query and give it a name, e.g., "Custom Field Query."
Create a chart for the query: Next, create a chart for the query you just created:
Navigate to the "Dashboards" section and click on "New Chart."
Select the "Query-based chart" option.
Choose the query you created in step 1 (e.g., "Custom Field Query").
Select the chart type you want to use (e.g., "Column Chart" or "Pie Chart").
Configure the chart settings, such as the series and category fields. For example, you can use the custom field as the series and the work item type as the category.
Save the chart and give it a name, e.g., "Custom Field Chart."
Add the chart to a dashboard: Finally, add the chart to a dashboard:
Navigate to the dashboard where you want to add the chart.
Click on "Edit" and then "Add a widget."
Select the "Chart" widget and choose the chart you created in step 2 (e.g., "Custom Field Chart").
Configure the widget settings, such as the title and size.
Save the dashboard.
Now you have a dashboard tile that visualizes the custom field in a chart that looks like the chart for work items. You can customize the chart and widget settings to fit your needs.