I came across the following work item rule request for which the implementation is not so straight forward for those unfamiliar with tfs work item customization.
The request is to “have a "Resolution" field on our Bug work item that is used by developers to describe the changes made to resolve the issue. We'd like this field to be read-only for all states until the dev changes the state to "Resolved".
To implement that you would do the following within the bug.xml (can do the same using the Process template editor that is available with the team foundation power tools).
A. In field definition you use the WhenNotChanged rule.
<span style="color: #0000ff"><</span><span style="color: #800000">FIELD</span> <span style="color: #ff0000">name</span><span style="color: #0000ff">="Resolution"</span> <span style="color: #ff0000">refname</span><span style="color: #0000ff">="CompanyName.Common.Resolution"</span> <span style="color: #ff0000">type</span><span style="color: #0000ff">="HTML"</span><span style="color: #0000ff">></span>
<span style="color: #0000ff"><</span><span style="color: #800000">WHENNOTCHANGED</span> <span style="color: #ff0000">field</span><span style="color: #0000ff">="System.State"</span><span style="color: #0000ff">></span>
<span style="color: #0000ff"><</span><span style="color: #800000">READONLY</span> <span style="color: #0000ff">/></span>
<span style="color: #0000ff"></</span><span style="color: #800000">WHENNOTCHANGED</span><span style="color: #0000ff">></span>
This make the will not editable except when the transition changes.
B. Do the following in each transition, except in the transition of going from "Active" to "Resolved"
<span style="color: #0000ff"><</span><span style="color: #800000">TRANSITION</span> <span style="color: #ff0000">from</span><span style="color: #0000ff">=""</span> <span style="color: #ff0000">to</span><span style="color: #0000ff">="Active"</span><span style="color: #0000ff">></span>
<span style="color: #0000ff"><</span><span style="color: #800000">FIELDS</span><span style="color: #0000ff">></span>
<span style="color: #0000ff"><</span><span style="color: #800000">FIELD</span> <span style="color: #ff0000">refname</span><span style="color: #0000ff">="CompanyName.Common.Resolution"</span><span style="color: #0000ff">></span>
<span style="color: #0000ff"><</span><span style="color: #800000">READONLY</span> <span style="color: #0000ff">/></span>
<span style="color: #0000ff"></</span><span style="color: #800000">FIELD</span><span style="color: #0000ff">></span>
<span style="color: #0000ff"></</span><span style="color: #800000">FIELDS</span><span style="color: #0000ff">></span>
<span style="color: #0000ff"></</span><span style="color: #800000">TRANSITION</span><span style="color: #0000ff">></span>
...
<span style="color: #0000ff"><</span><span style="color: #800000">TRANSITION</span> <span style="color: #ff0000">from</span><span style="color: #0000ff">="Resolved"</span> <span style="color: #ff0000">to</span><span style="color: #0000ff">="Closed"</span><span style="color: #0000ff">></span>
<span style="color: #0000ff"><</span><span style="color: #800000">FIELDS</span><span style="color: #0000ff">></span>
<span style="color: #0000ff"><</span><span style="color: #800000">FIELD</span> <span style="color: #ff0000">refname</span><span style="color: #0000ff">="CompanyName.Common.Resolution"</span><span style="color: #0000ff">></span>
<span style="color: #0000ff"><</span><span style="color: #800000">READONLY</span> <span style="color: #0000ff">/></span>
<span style="color: #0000ff"></</span><span style="color: #800000">FIELD</span><span style="color: #0000ff">></span>
<span style="color: #0000ff"></</span><span style="color: #800000">FIELDS</span><span style="color: #0000ff">></span>
<span style="color: #0000ff"></</span><span style="color: #800000">TRANSITION</span><span style="color: #0000ff">></span>
C. In Resolved transition would want to make the field required
<span style="color: #0000ff"><</span><span style="color: #800000">TRANSITION</span> <span style="color: #ff0000">from</span><span style="color: #0000ff">="Active"</span> <span style="color: #ff0000">to</span><span style="color: #0000ff">="Resolved"</span><span style="color: #0000ff">></span>
<span style="color: #0000ff"><</span><span style="color: #800000">FIELDS</span><span style="color: #0000ff">></span>
<span style="color: #0000ff"><</span><span style="color: #800000">FIELD</span> <span style="color: #ff0000">refname</span><span style="color: #0000ff">="CompanyName.Common.Resolution"</span><span style="color: #0000ff">></span>
<span style="color: #0000ff"><</span><span style="color: #800000">REQUIRED</span> <span style="color: #0000ff">/></span>
<span style="color: #0000ff"></</span><span style="color: #800000">FIELD</span><span style="color: #0000ff">></span>
<span style="color: #0000ff"></</span><span style="color: #800000">FIELDS</span><span style="color: #0000ff">></span>
<span style="color: #0000ff"></</span><span style="color: #800000">TRANSITION</span><span style="color: #0000ff">></span>
D. You will probably want to add a Team project security group that would allow some power users will to be able to edit the value. At a minimum you would do this in the Field rule.
Example:
<span style="color: #0000ff"><</span><span style="color: #800000">READONLY</span> <span style="color: #ff0000">not</span><span style="color: #0000ff">="[Project]\Project Administrators"</span> <span style="color: #0000ff">/></span>
The WhenNotChanged rules is well explained on MSDN
As a side note, for some creative usage of work item rules engine, I recommend reading the series of posts from the WIT Tools blog
Also to finalize my commentary, from an ALM point of view, I am not a great fan of putting field to read only (or putting group security to restrict edition of some field for that matter). Isn't preferable to empower all the members on the team and making them responsible to follow the agreed upon process. You can also easily track changes through the work item history or set specific TFS work item alert so investigate when the process might not be followed properly. But I understand that in certain organization cultures this type of implementation is necessary.
Bertrand