skip to Main Content

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:

  1. using the WorkItemTrackingRestClient’s getWorkItems method see
  2. setting WorkItemExpand.All in the request
  3. not listing any field names in the request
  4. 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


  1. Chosen as BEST ANSWER

    Answering my own question to prevent wasting anyone else's time. A couple observations that contributed to the perfect storm of misunderstanding:

    1. Azure only returns fields that have data
    2. ApiWorkItem._links.fields only lists declared fields in the project and provides no data
    3. getWorkItemsBatch and getWorkItems are two sides of the same coin, returning same set of data
    4. in the fields parameter of said methods the field's full referenceName is required, e.g. Microsoft.VSTS.Scheduling.OriginalEstimate and not just OriginalEstimate
    5. and most importantly one has to make sure they check against a work item that actually has data in the fields they need

    Everything works as intended..


  2. 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

    • This method returns only core fields.
    • WorkItemExpand.All expands only references (links to other work items, definitions) of a work item.
    • I think, the method is based on the following rest API: Get Work Items Batch

    You can find a raw sample of using it (Get list of work items for specific fields):

    {
      "ids": [
        297,
        299,
        300
      ],
      "fields": [
        "System.Id",
        "System.Title",
        "System.WorkItemType",
        "Microsoft.VSTS.Scheduling.RemainingWork"
      ]
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search