0
votes

I am trying to automate the creation and managing of TFS items. I have the following code to create a TFS item:

try
{
    Uri collectionUri = new Uri("http://TFSServer:8080");
    TfsTeamProjectCollection tpc = new TfsTeamProjectCollection(collectionUri);

    WorkItemStore workItemStore = tpc.GetService<WorkItemStore>();
    Project teamProject = workItemStore.Projects["ProjectName"];
    WorkItemType workItemType = teamProject.WorkItemTypes["ProjectNameTask"];

    WorkItem userStory = new WorkItem(workItemType)
    {
        Title = "Recently ordered menu 2",
        Description = "As a return customer, I want to see items that I've recently ordered",
        State = "Proposed"

    };

    var invalidFields = userStory.Validate();

    userStory.Save();
}
catch (Exception exception)
{
    Console.WriteLine("Exception occurred: " + exception.ToString());
    throw;
}

The call userStory.Validate() is returning one item in invalidFields with details:

Name: Issue Type
ReferenceName: IssueType

But, WorkItem does not have an element of type IssueType. So the following code is giving a compilation error:

WorkItem userStory = new WorkItem(workItemType)
{
    Title = "Recently ordered menu 2",
    Description = "As a return customer, I want to see items that I've recently ordered",
    State = "Active",
    IssueType = "Some Issue"

};

with error saying "Cannot resolve symbol 'IssueType'". This might be because I dont have access to the right dlls for the specific TeamProject. I think resolving one of the following two ideas might help:

How can I get the correct dlls for a specific TeamProject's WorkItem?

or

Is it possible to add a field to an object type? I tried to create a new class by extending WorkItem, but it is a sealed class in the namespace Microsoft.TeamFoundation.WorkItemTracking.Client.

Wondering how to resolve the issue.

1
Can you check what's the status of invalid field? - e.g.invalidFields[0].Status ?Michael
You should use a valid Work Item Type instead of ProjectNameTaskReza Aghaei
@Michael the invalidFields[0].Status is showing InvalidEmpty.Romonov

1 Answers

0
votes

A work item can have arbitrary fields far beyond what's expressed in the WorkItem type. Look in the Fields property for the field you're after.

For example, userStory.Fields["IssueType"].Value = "Value"