There are times when you want modify a work item so that the value of an HTML string field, like the Description field on a Requirement, has some default value when a new work item is created. You may also want to put some formatting on some or all of this text.
I was working with a customer that wanted to have a “template” for data security that would help the Business Analysts be more consistent in their requirement documentation. We added some bold template text that would be used as a reminder. The BA would just add the field name and security requirements in plain text next to the defaulted labels.
To get this effect we set the DEFAULT rule on the underlying HTML field to a string of HTML that will get rendered at runtime. There are two ways that you can enter the HTML to be rendered, through the Process Template Editor or directly within the work item type definition file. Please note the caveat at the end of this article so you don’t get burned by a limitation of the work item definition schema.
Using the Process Template Editor
When using the Process Template Editor you need to create a DEFAULT rule for your field. In the FROM field select “value” and in the VALUE field you enter your HTML fragment. In this editor you can enter your HTML just like you would in Visual Studio. When you hit OK to close the DEFAULT dialog it will escape all of the special characters in the HTML fragment.
Editing the Work Item Type Definition directly
If you edit the work item type definition directly, you have to escape all of the “special” characters so that they don’t interfere with the raw XML surrounding them. When uploaded to TFS, the escaped entries will be converted to HTML tags that can be rendered at runtime.
1: <FIELD name="Security" refname="MyCompany.Security" type="HTML">
2: <DEFAULT from="value" value="<b>Field Name:&nbsp;</b><br/><b>Security:&nbsp;</b><br/><br/><b>Field Name:&nbsp;</b><br/><b>Security:&nbsp;</b>" />
There is one thing that really limits the usefulness of this technique. There is a limit of 255 characters in the value attribute of the DEFAULT element. This limit is imposed when you import the work item type definition into the team project, so you have to be aware of this when using the Process Template Editor as the text entered there will be escaped on save and could easily go over the character limit.