Bruce McLeod
Bruce McLeod

Reputation: 1382

Populating the TFS WorkItem revisions collection

I am writing a tool that needs to access all the revisions of a TFS workitem template.

The Workitem has a Revisons collection, and Rev property that returns the number of revisions.

When I try and do a foreach through the collection, even though it contains 6 "entries" in my test workitem, the collection is empty.

To work around this I am using the GetWorkItem(WorkItemID, RevisionID), incrementing the revision ID in a for loop to get the revisions. It seems crazy taht I have to do this and there collection that doesn't contain what it is supposed to.

Am I missing something here, or is this simply a bug in the TFS client API.

Upvotes: 1

Views: 2698

Answers (4)

Ryan
Ryan

Reputation: 4662

Where are you getting the workitem? I know when I was getting version history of files with sourceControl.QueryHistory I had to set one of my parameters (bool include Changes) to true in order to get the changes in the changeset.

Upvotes: 0

user251316
user251316

Reputation: 1

I'm using the Microsoft.TeamFoundation.Controls.PickWorkItemsControl to select the work items I need. After that the revsionsCollectoin is compleet. Maybe this helps:

// select the workitems using the picker
ArrayList workItems = _workItemPicker.Control.SelectedWorkItems();

// after that use a foreach and output all history included in each revision
private void PrintHistory(WorkItem workitem)
{

        RevisionCollection revisions = workitem.Revisions;

        foreach (Revision revision in revisions)
        {
            String history = (String) revision.Fields["History"].Value;
            Console.WriteLine("**** Revision {0}", revision.Fields["Title"], revision.Fields["Changed Date"]);

            foreach (Field field in revision.Fields)
            {
                Console.WriteLine("* field {0}:{1} ", field.Name, field.Value);
            }

            Console.WriteLine("****");
            Console.WriteLine();
        }

} 

Upvotes: -1

Bruce McLeod
Bruce McLeod

Reputation: 1382

After much digging, it is quite clear to me now that if you want to get all the revisions of a work item, you must explicitly load the revision(2) that you want, and this makes the revisions collection pretty much useless.

Upvotes: 2

William D. Bartholomew
William D. Bartholomew

Reputation: 744

Depending on how your retrieving the work item it may only be partially loaded. Try calling the Open method on the work item before accessing the Revisions collection.

Upvotes: 0

Related Questions