While looking at a work item query in Excel, it became obvious that the classifying word I had used as a prefix on the names of my custom fields made viewing the data in Excel difficult – the columns needed to be wider than normal to see the field name.
As you probably know, once you’ve defined a work item field in a work item type definition it cannot be changed. These fields were being used, i.e. they had data in them and the reference names were being referred to in code, which meant I couldn’t just delete them and start again, so I came up with this way of ‘changing’ a work item field definition without losing the data.
Step 1. Create another field of the same type with a different name and refname and include a rule to copy the old to the new
<!–TODO: Rename this field –>
<FIELD type="Integer" name="TestingSync DefectId" refname="Custom.TestingSync.DefectId">
<HELPTEXT>The Quality Center Defect Id</HELPTEXT>
</FIELD>
<!–TODO: Remove this field –>
<FIELD type="Integer" name="Temp_TestingSync DefectId" refname="Custom.TestingSync.TempDefectId">
<COPY from="field" value="Custom.TestingSync.DefectId" />
</FIELD>
Step 2. Upload the template (not forgetting to refresh your client cache), then open all affected work items in Excel, show both the old and the new columns and History. Add a comment to the History field and publish the work items. Refresh, check the new field and if not populated, do it again. The data should now have been copied to the new field.
Step 3. Remove the original field from the WIT along with the copy rule and republish the WIT
<!–TODO: Rename this field
<FIELD type="Integer" name="TestingSync DefectId" refname="Custom.TestingSync.DefectId">
<HELPTEXT>The Quality Center Defect ID</HELPTEXT>
</FIELD>–>
<!–TODO: Remove this field –>
<FIELD type="Integer" name="Temp_TestingSync DefectId" refname="Custom.TestingSync.TempDefectId">
<!–<COPY from="field" value="Custom.TestingSync.DefectId" />–>
</FIELD>
Step 4. Delete the original field
witfields delete /s:http://tfs:8080 Custom.TestingSync.DefectId
Step 5. Reintroduce the original field, with it’s alterations, copying the data from the temporary field
<!–TODO: Remove copy rule –>
<FIELD type="Integer" name="Defect Id (QC)" refname="Custom.TestingSync.DefectId">
<HELPTEXT>The Quality Center Defect Id</HELPTEXT>
<COPY from="field" value="Custom.TestingSync.TempDefectId" />
</FIELD>
<!–TODO: Remove this field –>
<FIELD type="Integer" name="Temp_TestingSync DefectId" refname="Custom.TestingSync.TempDefectId" />
Step 6. Upload the template, open all affected work items in Excel, show both the columns and History. Add a comment to the History field and publish the work items. Refresh, check the new ‘amended’ field and if not populated, do it again. The data should now have been copied back into the ‘amended’ field.
Step 7. Remove the temporary field and the copy rule and republish the WIT
<FIELD type="Integer" name="Defect Id (QC)" refname="Custom.TestingSync.DefectId">
<HELPTEXT>The Quality Center Defect Id</HELPTEXT>
<!–<COPY from="field" value="Custom.TestingSync.TempDefectId" />–>
</FIELD>
<!–TODO: Remove this
<FIELD type="Integer" name="Temp_TestingSync DefectId" refname="Custom.TestingSync.TempDefectId" />–>
Step 8. Delete the temporary field
witfields delete /s:http://tfs:8080 Custom.TestingSync.TempDefectId
This can also be used to change the type of the field, say from String to Integer, but copy rules wont work in this scenario and you’ll have to use a bulk copy and paste in Excel instead.
Disclaimer: While this worked for me, I recommend you trial this on your test system to work out any kinks first