tags:

views:

285

answers:

2

I am attempting to import items from a legacy issue tracking system stored in an Excel sheet into Team Foundation Server. I loop through the rows of the Excel file successfully, and I can create new work items, but they are always in the Proposed state. If I attempt to change the state to Closed, then call the Validate method for the work item, I receive a validation error on the State property - InvalidListValue{4}.

    Dim MyProj As Project = store.Projects("MyProject")
    Dim WIT As WorkItemType = MyProj.WorkItemTypes("Task")
    Dim WorkItem As WorkItem = WIT.NewWorkItem()

    WorkItem.Title = Title
    WorkItem.Description = Description
    WorkItem.History = History
    WorkItem.State = "Closed"
    WorkItem.Fields("Assigned To").Value = AssignedTo
    WorkItem.Fields("Priority").Value = Priority
    WorkItem.Fields("Closed By").Value = ClosedBy

I have also tried the code below, attempting to save the work item, change the State to closed, and save it again, but this doesn't appear to work either - the State is still Proposed when I open it up under the My Work Items TFS query:

        WorkItem.Save()

        WorkItem.State = "Closed"
        WorkItem.Fields("Closed By").Value = ClosedBy
        WorkItem.Save()

Has anyone else tried such a thing and succeeded, or have ideas for doing it? Oh, and this is a CMMI task that I am trying to create and close. I wonder if I'm trying to skip over certain activities required by CMMI, but I'm new to this, and that's just a guess.

A: 

I figured out how to create and close a TFS CMMI task programmatically. The key was to go through the CMMI process, which can be found at http://msdn.microsoft.com/en-us/library/bb668962.aspx, changing the State propery and saving the WorkItem after each change.

        ... WorkItem creation tasks
        WorkItem.Fields("Assigned To").Value = AssignedTo
        WorkItem.Fields("Priority").Value = Priority

        'This first Save creates a WorkItem in the Proposed state'
        WorkItem.Save()

        WorkItem.State = "Active"
        Errors = WorkItem.Validate()
        WorkItem.Save()

        WorkItem.State = "Resolved"
        WorkItem.Fields("Resolved By").Value = ClosedBy
        WorkItem.Fields("Resolved Reason").Value = "Just because"
        Errors = WorkItem.Validate()
        WorkItem.Save()

        WorkItem.State = "Closed"
        WorkItem.Fields("Closed By").Value = ClosedBy
        Errors = WorkItem.Validate()
        WorkItem.Save()
Scott
A: 

You should use the TFS Integration Platform for this.

http://tfsintegration.codeplex.com/

MrHinsh