How Rules are Evaluated
You can gain some idea of how rules are evaluated when you apply multiple rules to a field. How rules are evaluated is not completely deterministic. This section describes the expected behavior and interactions when you are using the <WHEN*>, <DEFAULT>, and <COPY> rules.
The following steps show, in the correct sequence, the interactions that are performed by Team Foundation Server and by the user of a work-item form. Only steps 1, 8, and 13 are performed by the user.
Using the Visual Studio user interface, the user creates a new work item or edits an existing work item.
Fill in field defaults. For all fields, use any <DEFAULT> rules that are outside <WHEN*> rules.
Copy field values. For all fields, use any <COPY> rules that are outside <WHEN*> clauses.
For all fields with a <WHEN> rule that matches, first do <DEFAULT> and then <COPY> rules inside.
For all fields with a <WHENNOT> rule that matches, first do <DEFAULT> and then <COPY> rules inside.
The Team Foundation Server always processes <WHEN> rules before <WHENNOT> rules.
For all fields that have had their values changed since step 1 and that contain <WHENCHANGED> rules, first do <DEFAULT> and then <COPY> rules inside.
Allow the user to start editing.
The user changes a field value and then moves focus from the field.
Raise any <WHEN> rules for that field that match the new value.
Raise any <WHENNOT> rules for that field that match the new value.
Raise any <WHENCHANGED> rules for that field that match the new value.
Return editing ability to the user.
The user saves the changes to the database.
For all fields, perform <SERVERDEFAULT> operations that are defined for the field either directly or indirectly under a <WHEN> or a <WHENNOT> rule.
When a user uses the graphical user interface to modify a work-item form, a new value is set every time that a keystroke is entered for a field. This means that a <WHEN*> rule can occur unexpectedly whenever the rule’s prerequisite conditions are met.
In the following XML example, SubStatus will be emptied as you type "Approved Again" into the Status field because the <WHEN*> rule occurs as soon as the user types the letter "e" in Approved, even if the intended final value is not "Approve". For this reason, think carefully when you are using conditional rules.
<FIELD refname="MyCorp.SubStatus" /> <WHEN field="MyCorp.Status" value="Approve" > <EMPTY /> </WHEN> </FIELD>