THIS came closest to what I’m facing, but their solution doesn’t do the trick. Also it’s 2.5 years old, so maybe there’ve been some changes on the API so I’m opening a new question.
Here’s my manifest:
{
"targets": [
{
"id": "Microsoft.VisualStudio.Services"
}
],
"scopes": [
"vso.work_full",
"vso.project_manage",
"vso.profile",
"vso.graph",
"vso.identity"
],
"categories": [
"Azure Boards"
],
"demands": [
"api-version/6.0"
],
...
"contributions": [
{
"id": "",
"type": "ms.vss-web.hub",
"targets": [
"ms.vss-work-web.work-hub-group"
]
}
]
}
and my code:
import { getClient } from 'azure-devops-extension-api';
import { WorkItem, WorkItemExpand, WorkItemTrackingRestClient } from 'azure-devops-extension-api/WorkItemTracking';
export class WorkItemsService {
...
static async getWorkItems(ids: number[], projectId: string): Promise<WorkItem[]> {
const client = getClient(WorkItemTrackingRestClient);
...
client.getWorkItems(ids.slice(...), projectId, undefined, undefined, WorkItemExpand.All));
...
}
}
I’m:
- using the WorkItemTrackingRestClient’s
getWorkItems
method see - setting
WorkItemExpand.All
in the request - not listing any field names in the request
- setting
vso.work_full
in the manifest see
However I’m only getting these fields back:
"System.Id": "",
"System.AreaId": "",
"System.AreaPath": "",
"System.TeamProject": "",
"System.NodeName": "",
"System.AreaLevel1": "",
"System.Rev": "",
"System.AuthorizedDate": "",
"System.RevisedDate": "",
"System.IterationId": "",
"System.IterationPath": "",
"System.IterationLevel1": "",
"System.IterationLevel2": "",
"System.WorkItemType": "",
"System.State": "",
"System.Reason": "",
"System.AssignedTo": "",
"System.CreatedDate": "",
"System.CreatedBy": "",
"System.ChangedDate": "",
"System.ChangedBy": "",
"System.AuthorizedAs": "",
"System.PersonId": "",
"System.Watermark": "",
"System.CommentCount": "",
"System.Title": "",
"Microsoft.VSTS.Common.StateChangeDate": "",
"Microsoft.VSTS.Common.ActivatedDate": "",
"Microsoft.VSTS.Common.ActivatedBy": "",
"Microsoft.VSTS.Common.Priority": "",
"System.Parent": ""
But interestingly when I put the URL from the ApiWorkItem._links.fields
in a browser I get a humongous data set with all the fields I’m interested in and then some, similar to this. Case in point, Microsoft.VSTS.Scheduling.xxxx
. In the native method’s data it’s nowhere to be seen but in the JSON returned by the URL there’s a bunch of fields.
When instead of undefined
I put for example Effort
as in Microsoft.VSTS.Scheduling.Effort
, like so
client.getWorkItems(ids.slice(...), projectId, ['Effort']);
the results’ fields turn out empty.
I don’t feel like making hundreds of API calls to get the data I need from the work items’ URLs. What am I missing?
I appreciate anyone who read this far.
2
Answers
Answering my own question to prevent wasting anyone else's time. A couple observations that contributed to the perfect storm of misunderstanding:
ApiWorkItem._links.fields
only lists declared fields in the project and provides no datagetWorkItemsBatch
andgetWorkItems
are two sides of the same coin, returning same set of datafields
parameter of said methods the field's fullreferenceName
is required, e.g.Microsoft.VSTS.Scheduling.OriginalEstimate
and not justOriginalEstimate
Everything works as intended..
As I understand, you are trying to use this method: https://learn.microsoft.com/en-us/javascript/api/azure-devops-extension-api/workitemtrackingrestclient#azure-devops-extension-api-workitemtrackingrestclient-getworkitems
You can find a raw sample of using it (Get list of work items for specific fields):