Accessing work item history from API

How do I access the work item history from the API

I want to traverse the history of the work item by entry if possible.

If it is not possible, a string with all the history will help too.

Thanks




Answer this question

Accessing work item history from API

  • Chris242

    Thanks for your answers.

    I was able to traverse the revisions in the way described on the last post.

    Thanks again,

    Pablo



  • Den1se

    I'm thinking that Pablo is asking how to get all of the information from the History tab -- not just the text entered from "Type your comment here." (i.e. the WorkItem.History property).

    You could iterate through the WorkItem.Revisions property and then iterate through the Fields collection for each revision, and display any values that changed between adjacent revisions.

    If you want to know the timestamp of the revision and the user that made the change, it looks like you'd use rev["Changed Date"] and rev["Changed By"].

    -Larry


  • BFC

    no problem :)

  • HarrisTL

    here some example:

    foreach(Revision rev in wrkitem.Revisions)

    {

    foreach(Field f in rev.Fields)

    {

    Console.WriteLine("{0} = {1}\n",f.Name,f.Value);
    }
    }



  • Zak Jensen

    Hello

    You can fetch the work item of a particular revision from Work Item Store and then access the History Field to get the History. A sample code is here:

    WorkItem wi1 = WIStore.GetWorkItem(wi.Id);

    wi1.Open();

    wi1.Title = testTitle + "Random Text";

    wi1.Description = testDesc + "Random Text";

    wi1.History = "Random Text";

    int revisionNumber = wi1.Revision;

    wi1.Save();

    WIStore.RefreshCache();

    WorkItem wi2 = WIStore.GetWorkItem(wi.Id, revisionNumber + 1);

    String historyText = wi2.History;

    Please let me know if you need any additional information on this.

    Thanks

    Sagar



  • Kafmil

    There is OriginalValue property on fields as well, so you can use something like

    foreach(Field f in rev.Fields)
    {
    if(!Object.Equals(f.Value, f.OriginalValue))
    {
    Console.WriteLine("{0}: {1} -> {2}", f.Name, f.OriginalValue, f.Value);
    }
    }

    History control creates Field Change tables when clicking on expand button.


  • Accessing work item history from API