Forum Discussion
Abdul_ur_Rehman
Jan 10, 2024Copper Contributor
How to revert back WorkItems' old component after changing them to new component
I mistakenly changed the components of different areas to a single component. I created a query for components without realizing that there was a mistake in the query and changed the components of al...
Kidd_Ip
Jul 07, 2025MVP
How about this:
1. Get Affected Work Item IDs
Use your WIQL query to get the list of affected work items:
GET https://dev.azure.com/{organization}/{project}/_apis/wit/wiql/{queryId}?api-version=6.0
Extract the workItemIds from the response.
2. Fetch Work Item History
For each work item ID, call:
GET https://dev.azure.com/{organization}/{project}/_apis/wit/workItems/{id}/updates?api-version=5.1
- Look for the update where the Component field (or whatever custom field name you're using) was changed.
- Extract the old value from the fields["System.AreaPath"].oldValue or your custom field.
3. Prepare a Patch Payload
Once you have the old value, use a PATCH request to update the work item:
PATCH https://dev.azure.com/{organization}/{project}/_apis/wit/workitems/{id}?api-version=6.0
Content-Type: application/json-patch+json
[
{
"op": "add",
"path": "/fields/Custom.Component",
"value": "OldComponentValue"
}
]
Replace Custom.Component with your actual field reference name.
4. Automate with a Script
Use PowerShell, Python, or a tool like Postman Collection Runner to automate this for all 13K items. Here's a Python snippet using requests:
import requests
from requests.auth import HTTPBasicAuth
PAT = 'your_personal_access_token'
headers = {
'Content-Type': 'application/json-patch+json'
}
def revert_component(work_item_id, old_value):
url = f"https://dev.azure.com/your_org/your_project/_apis/wit/workitems/{work_item_id}?api-version=6.0"
payload = [{
"op": "add",
"path": "/fields/Custom.Component",
"value": old_value
}]
response = requests.patch(url, json=payload, headers=headers, auth=HTTPBasicAuth('', PAT))
return response.status_code
# Loop through your work items and call revert_component