Rickson
Rickson

Reputation: 1090

Copying Work Items in TFS 2015

We are using TFS 2015 and the CMMI process template.

I am trying to find out how to create a full copy from an Issue work item whereby the target work item type should be Requirement. With full copy I mean that the values of all fields of the Issue that are also available within the Requirement (e.g. Title, Description, State, Area Path, Iteration,...) should be copied as well as all links to other work items (child, parent, related, successor, predecessor, etc.).

Using "Copy" within VSO will f.e. not copy child links of the Issue (Tasks). Instead it creates a "related" to the source Issue...

Any recommendation how this can be realized would be highly appreciated.

Upvotes: 3

Views: 848

Answers (2)

Eddie Chen - MSFT
Eddie Chen - MSFT

Reputation: 29968

When you select the "Create copy of work item", VSO cannot determine the relationship between the source work item and target work item, so it just create "Related" relationship between them. You can update it manually after the work item is copied. And you can also submit a User Voice for adding a relationship select option on "Copy Workitem" dialog.

For now, the way to do this automatically is using TFS API or VSO Rest API to read and record the detailed information about the source work item, change the information you want (Work item type, relationship) and then create a new work item base on the new information.

Upvotes: 2

chief7
chief7

Reputation: 14383

You can use the TFS API to read a test cases from TFS and then create a new one based on the properties you wish to copy over. Here is some sample code for creating a Test Case:

   using System;
using Microsoft.TeamFoundation.Client;
using Microsoft.TeamFoundation.WorkItemTracking.Client;

namespace WorkItemTrackingSample
{
    class Program
    {
        static void Main(string[] args)
        {            // Connect to the server and the store, and get the WorkItemType object
            // for user stories from the team project where the user story will be created. 
            Uri collectionUri = (args.Length < 1) ?
                new Uri("http://server:port/vdir/DefaultCollection") : new Uri(args[0]);
            TfsTeamProjectCollection tpc = new TfsTeamProjectCollection(collectionUri);
            WorkItemStore workItemStore = tpc.GetService<WorkItemStore>();
            Project teamProject = workItemStore.Projects["DinnerNow"];
            WorkItemType workItemType = teamProject.WorkItemTypes["Test Case"];

            // Create the work item. 
            WorkItem userStory = new WorkItem(workItemType)
            {
                // The title is generally the only required field that doesn’t have a default value. 
                // You must set it, or you can’t save the work item. If you’re working with another
                // type of work item, there may be other fields that you’ll have to set.
                Title = "Recently ordered menu",
                Description =
                    "As a return customer, I want to see items that I've recently ordered."
            };

            // Save the new user story. 
            userStory.Save();
        }
    }
}

Upvotes: 2

Related Questions