WI customization: how to allow field editions at specific states

Posted by InCycle - May 31, 2009

header-picture

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">&lt;</span><span style="color: #800000">FIELD</span> <span style="color: #ff0000">name</span><span style="color: #0000ff">=&quot;Resolution&quot;</span> <span style="color: #ff0000">refname</span><span style="color: #0000ff">=&quot;CompanyName.Common.Resolution&quot;</span> <span style="color: #ff0000">type</span><span style="color: #0000ff">=&quot;HTML&quot;</span><span style="color: #0000ff">&gt;</span> 
    <span style="color: #0000ff">&lt;</span><span style="color: #800000">WHENNOTCHANGED</span> <span style="color: #ff0000">field</span><span style="color: #0000ff">=&quot;System.State&quot;</span><span style="color: #0000ff">&gt;</span> 
    <span style="color: #0000ff">&lt;</span><span style="color: #800000">READONLY</span> <span style="color: #0000ff">/&gt;</span> 
<span style="color: #0000ff">&lt;/</span><span style="color: #800000">WHENNOTCHANGED</span><span style="color: #0000ff">&gt;</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">&lt;</span><span style="color: #800000">TRANSITION</span> <span style="color: #ff0000">from</span><span style="color: #0000ff">=&quot;&quot;</span> <span style="color: #ff0000">to</span><span style="color: #0000ff">=&quot;Active&quot;</span><span style="color: #0000ff">&gt;</span> 
    <span style="color: #0000ff">&lt;</span><span style="color: #800000">FIELDS</span><span style="color: #0000ff">&gt;</span> 
        <span style="color: #0000ff">&lt;</span><span style="color: #800000">FIELD</span> <span style="color: #ff0000">refname</span><span style="color: #0000ff">=&quot;CompanyName.Common.Resolution&quot;</span><span style="color: #0000ff">&gt;</span> 
            <span style="color: #0000ff">&lt;</span><span style="color: #800000">READONLY</span> <span style="color: #0000ff">/&gt;</span> 
       <span style="color: #0000ff">&lt;/</span><span style="color: #800000">FIELD</span><span style="color: #0000ff">&gt;</span> 
    <span style="color: #0000ff">&lt;/</span><span style="color: #800000">FIELDS</span><span style="color: #0000ff">&gt;</span> 
<span style="color: #0000ff">&lt;/</span><span style="color: #800000">TRANSITION</span><span style="color: #0000ff">&gt;</span> 
...
<span style="color: #0000ff">&lt;</span><span style="color: #800000">TRANSITION</span> <span style="color: #ff0000">from</span><span style="color: #0000ff">=&quot;Resolved&quot;</span> <span style="color: #ff0000">to</span><span style="color: #0000ff">=&quot;Closed&quot;</span><span style="color: #0000ff">&gt;</span> 
    <span style="color: #0000ff">&lt;</span><span style="color: #800000">FIELDS</span><span style="color: #0000ff">&gt;</span> 
        <span style="color: #0000ff">&lt;</span><span style="color: #800000">FIELD</span> <span style="color: #ff0000">refname</span><span style="color: #0000ff">=&quot;CompanyName.Common.Resolution&quot;</span><span style="color: #0000ff">&gt;</span> 
            <span style="color: #0000ff">&lt;</span><span style="color: #800000">READONLY</span> <span style="color: #0000ff">/&gt;</span> 
        <span style="color: #0000ff">&lt;/</span><span style="color: #800000">FIELD</span><span style="color: #0000ff">&gt;</span> 
    <span style="color: #0000ff">&lt;/</span><span style="color: #800000">FIELDS</span><span style="color: #0000ff">&gt;</span> 
<span style="color: #0000ff">&lt;/</span><span style="color: #800000">TRANSITION</span><span style="color: #0000ff">&gt;</span> 

C. In Resolved transition would want to make the field required

 

<span style="color: #0000ff">&lt;</span><span style="color: #800000">TRANSITION</span> <span style="color: #ff0000">from</span><span style="color: #0000ff">=&quot;Active&quot;</span> <span style="color: #ff0000">to</span><span style="color: #0000ff">=&quot;Resolved&quot;</span><span style="color: #0000ff">&gt;</span> 
    <span style="color: #0000ff">&lt;</span><span style="color: #800000">FIELDS</span><span style="color: #0000ff">&gt;</span> 
        <span style="color: #0000ff">&lt;</span><span style="color: #800000">FIELD</span> <span style="color: #ff0000">refname</span><span style="color: #0000ff">=&quot;CompanyName.Common.Resolution&quot;</span><span style="color: #0000ff">&gt;</span> 
            <span style="color: #0000ff">&lt;</span><span style="color: #800000">REQUIRED</span> <span style="color: #0000ff">/&gt;</span> 
        <span style="color: #0000ff">&lt;/</span><span style="color: #800000">FIELD</span><span style="color: #0000ff">&gt;</span> 
    <span style="color: #0000ff">&lt;/</span><span style="color: #800000">FIELDS</span><span style="color: #0000ff">&gt;</span> 
<span style="color: #0000ff">&lt;/</span><span style="color: #800000">TRANSITION</span><span style="color: #0000ff">&gt;</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">&lt;</span><span style="color: #800000">READONLY</span> <span style="color: #ff0000">not</span><span style="color: #0000ff">=&quot;[Project]\Project Administrators&quot;</span> <span style="color: #0000ff">/&gt;</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

Topics: Blog


Recent Posts

InCycle Named Azure Data Explorer (ADX) Partner

read more

OpsHub & InCycle Help Top Medical Device Company Accelerate Innovation

read more

InCycle Continues to Lead, Recognized by Microsoft for Industry Innovation. Earns Impact Award.

read more