In our last post in this series, Gregg blogged about validating area path. Let’s take a look at another question: “How do I close an iteration so that no one can log new items against it?”
For this example, let’s say we have completed Iteration 0 and don’t want users to log work items against this iteration. We also don’t want to allow work items against the root iteration path.
Since there is no direct way to enforce rules against iteration path, here’s how we can work around it:
<FIELD type="String" name="Iteration Path Validation" refname="Demo.IterationPathValidation"> <COPY from="value" value="No Errors" /> <WHEN field="System.IterationId" value="113"> <COPY from="value" value="Iteration path must be 2 levels deep" /> </WHEN> <WHEN field="System.IterationId" value="115"> <COPY from="value" value="The selected iteration has been completed. Log bugs against a future iteration." /> </WHEN> <PROHIBITEDVALUES> <LISTITEM value="Iteration path must be 2 levels deep" /> <LISTITEM value="The selected iteration has been completed. Log bugs against a future iteration." /> </PROHIBITEDVALUES> </FIELD>
<FIELD type="String" name="Iteration Path Validation" refname="Demo.IterationPathValidation">
<COPY from="value" value="No Errors" />
<WHEN field="System.IterationId" value="113">
<COPY from="value" value="Iteration path must be 2 levels deep" />
</WHEN>
<WHEN field="System.IterationId" value="115">
<COPY from="value" value="The selected iteration has been completed. Log bugs against a future iteration." />
<PROHIBITEDVALUES>
<LISTITEM value="Iteration path must be 2 levels deep" />
<LISTITEM value="The selected iteration has been completed. Log bugs against a future iteration." />
</PROHIBITEDVALUES>
</FIELD>
The next step is to add this validation field to the work item form, let’s use the same form definition as the area path validation example. Here’s how the form would look when a user assigns a work item to Iteration 0:
The IterationPathValidation field shows a meaningful error message when a work item is assigned to the closed iteration.
How does this workaround work?
How do I find out the iteration ID?
If you have ideas on other workarounds or scenarios you want to accomplish, please let us know and we will post them here. We have a few more workarounds coming your way in the upcoming posts.
Sunder Raman
Program Manager, Team Foundation Server
[Update 4/23/2009] Thanks to one of our readers, Dylan for his comment that this workaround didn't work for him in TSWA. I reproed this workaround and we found the issue where Web Access isn't refreshing on WHEN rule. We are tracking this bug to be fixed in our upcoming release. Caution to users, if you are using TSWA, note that this workaround doesn't work in TSWA.