Making a work item field read only after its initial value has been set

Here's a neat little trick that Alex on my team came up with today to solve a customer problem. We wanted to be able to have a field on a work item form that was initially writable but, once set, couldn't be altered.

This is how you'd define the field in the Work Item Type definition XML file (Updated 8/17/05 to user REQUIRED and FROZEN rules instead of the WHENNOT rule)

     <FIELD name="MyField" refname="MyWorkItemNamespace.MyField" type="String">

All this does is say that as soon as the field is not empty, it will become read only.

This trick means that you can use the copy work item feature, and this field will still be copied over. Normally, if a field is always read only, it won't be written into when you create a copy of a work item.