views:

588

answers:

3

Hi I am trying to add new workitems to the TFS repository using the API, but when I validate the workitem before it is saved, it returns an error. I previously got exceptions regarding the field definitions for a bug namely, Symptom, Steps to Reproduce and Triage. (Error code TF 26027). The code snippet is shown below: Can anyone tell me what's wrong here?

switch (workItemType)
        {
            case "Bug":
                {
                    workItem.Title = values["Title"].ToString();
                    workItem.State = values["State"].ToString();
                    workItem.Reason = values["Reason"].ToString();
                    workItem.Fields["Priority"].Value = values["Priority"].ToString();
                    workItem.Fields["Severity"].Value = values["Severity"].ToString();
                    //workItem.Fields["Triage"].Value = values["Triage"].ToString();
                    workItem.Fields["Assigned To"].Value = values["Assigned To"].ToString();
                    //workItem.Fields["Symptom"].Value = values["Symptom"].ToString();
                    //workItem.Fields["Steps to Reproduce"].Value = values["Steps to Reproduce"].ToString();

                    // Validate the Work Item fields.
                    ArrayList result = workItem.Validate();
                    // If any invalid fields are returned, report an error.
                    if (result.Count > 0)
                        MessageBox.Show("An Error occurred while adding the Bug to the repository.");
                    else
                        workItem.Save();
                }
                break;
A: 

Just reading the error message it looks like you are defining a field called "somefield" in your work item. I'm thinking that you have some old code hanging around elsewhere, maybe above the code snippet you posted, where you are defining a value for workItem.Fields["somefield"]

Richard Banks
A: 

To find the available field definitions, you can iterate over the collection (FieldDefinitions). The Name and ReferenceName properties are the values you can index by into the collection.

Jim Lamb
This is a good idea anyways, you should always iterate and check for the field to exist. Because at least here, we have many different teams with customized templates. And you never know, from project to project what fields exist or not. Saves a lot of exception throwing.
Alex
A: 

the Field "Symptom" cannot be empty

zuoshanshan