Reputation: 1
I want to add a new field in my work item similar to roll up column so that it automatically calculates my story points ,it should automatically calculate my story points from child work items just like how it does in backlogs ,I can see this in backlog but due to some reasons i need to add it in my work item ,I have tried adding story points in process section in organization settings but that need to be manually filled but I need a field that auto calculates just like rollup column in column options, is it possible?
I tried creating a filed in process section in organization settings and added a filed named story points in feature but that needs to be manually filled, I want it to be auto calculated like how we have rollup column i.e sum of story points option in column options in backlog.
Upvotes: 0
Views: 286
Reputation: 6037
There is no build-in functionality to automatically populate a field of a feature with the total Story Points of its child user stories; while you may consider using REST API to Get the Story Points of each child user story of a feature and then Update the Story Points field of the parent feature with the total story points. Here is a PowerShell script for your reference.
$organization = "YourADOOrgName"
$project = "TheProjectName"
$featureId = "1866"
$MyPat = 'YourPersonalAccessToken'
$B64Pat = [Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes(":$MyPat"))
$headers = @{
'Authorization' = 'Basic ' + "$B64Pat"
'Content-Type' = 'application/json'
}
$featureURL = "https://dev.azure.com/$organization/$project/_apis/wit/workitems/$($featureId)?`$expand=all&api-version=7.2-preview.3"
$feature = Invoke-RestMethod -Method Get -Uri $featureURL -Headers $headers
$childUserStories = $feature.relations | Where-Object { $_.rel -eq 'System.LinkTypes.Hierarchy-Forward' }
$totalStoryPoints = 0
foreach ($childUserStory in $childUserStories) {
$userStoryURL = $childUserStory.url + "?api-version=7.2-preview.3"
$userStory = Invoke-RestMethod -Method Get -Uri $userStoryURL -Headers $headers
$storyPoints = $userStory.fields.'Microsoft.VSTS.Scheduling.StoryPoints'
Write-Host The story points of the child user story $userStory.id is $storyPoints
$totalStoryPoints += $storyPoints
}
Write-Host Total story points of the child user stories are $totalStoryPoints
$body = @(
@{
op = "replace"
path = "/fields/Microsoft.VSTS.Scheduling.StoryPoints"
value = $totalStoryPoints
}
)
$jsonBody = ConvertTo-Json $body -Depth 10
$response = Invoke-RestMethod -Method Patch -Uri $featureURL -Headers $headers -ContentType application/json-patch+json -Body $jsonBody
$response
Upvotes: 0
Reputation: 16133
You may use rollup for custom fields. Check this doc: Rollup for custom fields.
But that will be accessible only in the backlog view as a column. You should create an aggregation script through rest API or with az
command line if you want to use a separate field in your work item. As an example, you may:
Upvotes: 0