Harish
Harish

Reputation: 1

I want to add a new filed in my work item called story points similar to a rollup column (Sum of Story points), in azure boards, is it possible?

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

Answers (2)

Alvin Zhao - MSFT
Alvin Zhao - MSFT

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

enter image description here enter image description here

Upvotes: 0

Shamrai Aleksander
Shamrai Aleksander

Reputation: 16133

You may use rollup for custom fields. Check this doc: Rollup for custom fields.

enter image description here

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:

  1. Query the parent work items: az boards query
  2. Check their list of child work items: az boards work-item relation show
  3. Get your custom value from each child: az boards work-item show
  4. Add the summary value to the parent: az boards work-item update

Upvotes: 0

Related Questions