Search code examples
azure-devopsazure-pipelinesazure-devops-rest-apiazure-devops-extensions

Inconstancy in retrieving System.History field in Azure DevOps API


I am developing Azure DevOps extension. This extension has ability to create work items based on data retrieved from third party platform and update work items based on updated data in the platform. This platform has some dynamic data for each work item. Dynamic data are related to the state, tags, and history (comments) of the work item. So, whenever user runs build in ADO pipeline, retrieves and compare these dynamic data with specific work item and updates the work item status, tags and history.

I am using azure-devops-node-api npm package, and I am using WorkItemTrackingApi to get work item details.

getWorkItem(id: number, fields?: string[], asOf?: Date, expand?: WorkItemTrackingInterfaces.WorkItemExpand, project?: string): Promise<WorkItemTrackingInterfaces.WorkItem>;

Below are the fields I am expecting from above API call.

const fields: string[] = ["System.State", "System.Title", "System.Tags", "System.History"];

What I have observed was, this API call does not always successfully respond with the history (even though there is history available in work item). Where most of occasions history (workitem.fields["System.History"]) become undefined while work item is not null. This is not consistent as it randomly passing the history data in the response. Further, I didn’t observe this issue for any other fields such as title and tags.

Retrieving history is important for me as I am comparing data from platform with work item history and only adding new comment(history) to the work item based on data newly added in the platform. I believe this is bug in API as it is very inconsistent. Is there robust solution to this issue where I can always keep faith on retrieving history?


Solution

  • It looks like Microsoft has deprecated old way of retrieving history data instead they have introduced API method to retrieve comments list. I was able to resolve my issue by using new method.

    Old(deprecated): https://learn.microsoft.com/en-us/previous-versions/azure/devops/integrate/previous-apis/wit/history?view=tfs-2017&viewFallbackFrom=tfs-2018

    New: https://learn.microsoft.com/en-us/previous-versions/azure/devops/integrate/previous-apis/wit/comments?view=tfs-2017

    WorkItemTrackingApi interface: https://github.com/microsoft/azure-devops-node-api/blob/master/api/WorkItemTrackingApi.ts

    API Method to obtain comments:

     getComments(project: string, workItemId: number, top?: number, continuationToken?: string, includeDeleted?: boolean, expand?: WorkItemTrackingInterfaces.CommentExpandOptions, order?: WorkItemTrackingInterfaces.CommentSortOrder): Promise<WorkItemTrackingInterfaces.CommentList>;