I have created a non-standard customized work item in ADO called "Resource". I want to a method (assumed PowerShell script with ADO REST API) to do the following:
- Pull or loop through all work items of this "Resource" type within a Project.
- For each work item, Get the value on field "Value A" on that work item, cross reference to a table (hard coded or external) with both "Value A" and "Value B".
- Lookup "Value A" then get "Value B" field on the table and update "Value B" on the "Resource" work item.
Basically, it is a lookup request. This table of information may change monthly and would need to rerun.
My assumption is that Powershell is likely the best option, but not sure. Not sure if I have to hardcode the table or if I should call to an external table/database. This table would range from 100 to 500 rows with two columns..Value A and Value B.
Old programmer, but new to Powershell, seen examples of replace a single work item but nothing for a mass-changes, loop, or lookup/replace.
What I am asking seems possible but not sure if I am suggesting something that is simple through other methods. Powershell it seems possible, Power Automate another, or there might be something built into ADO I am not thinking of.
Again, hoping for insight of my problem if a Powershell is the best method, if it is possible, and if so...an example of the code.
I have created a non-standard customized work item in ADO called "Resource". I want to a method (assumed PowerShell script with ADO REST API) to do the following:
- Pull or loop through all work items of this "Resource" type within a Project.
- For each work item, Get the value on field "Value A" on that work item, cross reference to a table (hard coded or external) with both "Value A" and "Value B".
- Lookup "Value A" then get "Value B" field on the table and update "Value B" on the "Resource" work item.
Basically, it is a lookup request. This table of information may change monthly and would need to rerun.
My assumption is that Powershell is likely the best option, but not sure. Not sure if I have to hardcode the table or if I should call to an external table/database. This table would range from 100 to 500 rows with two columns..Value A and Value B.
Old programmer, but new to Powershell, seen examples of replace a single work item but nothing for a mass-changes, loop, or lookup/replace.
What I am asking seems possible but not sure if I am suggesting something that is simple through other methods. Powershell it seems possible, Power Automate another, or there might be something built into ADO I am not thinking of.
Again, hoping for insight of my problem if a Powershell is the best method, if it is possible, and if so...an example of the code.
Share Improve this question asked Jan 30 at 17:57 Ben NelsonBen Nelson 1 1- Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. – Community Bot Commented Jan 30 at 21:24
1 Answer
Reset to default 0Here is the demo how to get the field and update it.
$token = "Personal Access Token"
$url="https://dev.azure/{}/{project}/_apis/wit/wiql?api-version=7.1"
$token = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes(":$($token)"))
$JSON = @'
{
"query": "Select [System.Id], [System.Title], [System.State] From WorkItems Where [System.WorkItemType] = 'Epic'"
}
'@
$response = Invoke-RestMethod -Uri $url -Headers @{Authorization = "Basic $token"} -Method Post -Body $JSON -ContentType application/json
ForEach( $workitem in $response.workItems )
{
$workitemid= $workitem.id
$url1="https://dev.azure/{}/{project}/_apis/wit/workitems/$($workitemid)?api-version=7.1"
$response1 = Invoke-RestMethod -Uri $url1 -Headers @{Authorization = "Basic $token"} -Method Get
echo $response1.fields.'System.Title'
$body = @(
@{
"op" = "add"
"path" = "/fields/System.Title"
"value" = "Updated Title"
},
@{
"op" = "add"
"path" = "/fields/System.Description"
"value" = "Updated Description"
}
) | ConvertTo-Json -Depth 10
$response = Invoke-RestMethod -Uri $url1 -Method Patch -Headers @{
Authorization = "Basic $token"
"Content-Type" = "application/json-patch+json"
} -Body $body
$response
}
In the ForEach( $workitem in $response.workItems )
, you could get the Value B from hard coded or external.
And update it in
$body = @(
@{
"op" = "add"
"path" = "/fields/System.Title"
"value" = "Updated Title"
},
@{
"op" = "add"
"path" = "/fields/System.Description"
"value" = "Updated Description"
}
) | ConvertTo-Json -Depth 10