Create work items using TFS API?

Hi,

I'm trying to import all of our bugs from Bugzilla to TFS. I'm able to pull the data out of Bugzilla's MySQL DB just fine using C#, but how do I use the TFS API to import these bugs

I downloaded the TFS SDK and read through some samples, but they seem overly complicated. Can someone please post a very simple example in C# on how to create one work item Bug in TFS I can then take it from there.

I need to be referencing Microsoft.TeamFoundation.Client and Microsoft.TeamFoundation.WorkItemTracking.Client correct

Thanks,

Ethan


Answer this question

Create work items using TFS API?

  • Kartit

    Thanks. Now I am getting this exception on the workItem.Save() line:

    TF26201: This work item has unsupported fields, or user does not have permissions.

    I am assuming that this has to do with  custom fields I've added to our bugs. Any idea on an easy way to debug this I'm finding it tough trying to figure out which field is causing me the problems.

    Ethan


  • Ganeshkumar S

    Hello Ethan,

    You are in the right track.

    Below is quick sample.

    WorkItemStore store = new WorkItemStore("serverName");

    Project proj = store.Projects["projectName"];

    WorkItemType type = proj.WorkItemTypes["WorkItemType"];

    WorkItem workItem = new WorkItem(type);

    workItem.Title = "title";

    workItem["Field Name"] = "test";

    workItem.Save();

    Hope this helps,



  • Smealum

    Got it working... I was using the Ref Name for the field names instead of the actual Name. Thanks guys! Works great.

  • Jessica Alba

    You can also check http://www.goeleven.com/blog/entryDetail.aspx entry=35 for step-by-step instructions on adding right references.

  • Bisjom

    Does this happen when saving in UI Did you check validity of each field by looping through the fields and calling IsValid Most likely in the UI or by looping fields, it should say which field is causing the problem.

    If all fields are valid and if this still happens, it is likely because of conflicting rules or attempting to write to some fields which would be readonly at that moment (such as "changed date", "changed by" etc). In past I have seen it happen because of sending longer than maxallowed values for link uris, link comments etc - but I believe we fixed those issues. Server could also reject with this error based on its validation. Ofcourse another reason is permission as the error says.

    It might take a while to find which rules are conflicting. For examples, you can see below:

    <http://forums.microsoft.com/MSDN/ShowPost.aspx PostID=580695&SiteID=1>

    <http://forums.microsoft.com/MSDN/ShowPost.aspx PostID=797071&SiteID=1>

    <http://forums.microsoft.com/MSDN/ShowPost.aspx PostID=761280&SiteID=1>



  • Create work items using TFS API?