Change a TFS Work Item Definition

December 19, 2016

Let’s assume that the built-in TFS standard templates are not sufficient for you. You’re in luck: TFS allows you to create your own custom work item. Let’s imagine that, for some reason, you want a work item type called “Defect”, rather than “Bug”. Here’s the process, based on the “Bug” work item type.

First thing is to open the command prompt in administrator mode, and navigate to a work directory; for example, the “Documents” folder . Then export the template work item type, like so (you can export the entire definition of all work items, but it becomes unmanageable):

[code lang=“DOS”] witadmin exportwitd /collection:http://tlaptop:8080/tfs/DefaultCollection /p:“TFSSandbox” /n:Bug /f:Defect.xml




[![customwi1](http://pmichaels.net/wp-content/uploads/2016/11/CustomWI1-300x69.png)](http://pmichaels.net/wp-content/uploads/2016/11/CustomWI1.png)

Check your working directory:

[![customwi2](http://pmichaels.net/wp-content/uploads/2016/11/CustomWI2.png)](http://pmichaels.net/wp-content/uploads/2016/11/CustomWI2.png)

Now, open the XML file.  I used Notepad++, but you can use Notepad or vi, or whatever.  To change the work item, change the name attribute; once you've done this, you have a new work item type:

[![customwi3](http://pmichaels.net/wp-content/uploads/2016/11/CustomWI3-300x80.png)](http://pmichaels.net/wp-content/uploads/2016/11/CustomWI3.png)

Now, you can add the fields that you want.  I'm adding a field called "pcm.CustomField":
[code lang="XML"]
<?xml version="1.0" encoding="utf-8"?>
<witd:WITD application="Work item type editor" version="1.0" xmlns:witd="http://schemas.microsoft.com/VisualStudio/2008/workitemtracking/typedef">
  <WORKITEMTYPE name="Defect">
    <DESCRIPTION>Customised defect</DESCRIPTION>
    <FIELDS>
      <FIELD name="Iteration Path" refname="System.IterationPath" type="TreePath" reportable="dimension">
        <HELPTEXT>The iteration within which this bug will be fixed</HELPTEXT>
      </FIELD>
	  <FIELD name="New Field" refname="pcm.CustomField" type="Integer" />
      <FIELD name="Iteration ID" refname="System.IterationId" type="Integer" />

The field name attribute (“New Field” in this case) tells TFS how to refer to this field to the user. This is important, because if you forget that you’ve called it “New Field”, you might assume this hasn’t worked and start googling to find out why.

Now you’ve told TFS that you have a field to store; the next step is to add that field to the layout:

[code lang=“XML”]




As you can see, we can move this about and pretty much show anything we want here.  Next, re-import:

[code lang="DOS"]
witadmin importwitd /collection:http://tlaptop:8080/tfs/DefaultCollection /p:TFSSandbox /f:Defect.xml

customwi5

Using the new Work Item Type

And now we have a new work item type:

customwi6

And the new field is available:

customwi7

Using The Field in a Query

customwi8

References

Tutorial on modifying Work Item States

Tutorial on customising TFS 2013

Detailed definition of the FIELD tag

Turotial on modifying the FIELD tag



Profile picture

A blog about one man's journey through code… and some pictures of the Peak District
Twitter

© Paul Michaels 2022